TensorFlow 是一个深度学习框架,支持 Linux 平台,Windows 平台,Mac 平台,甚至手机移动设备等各种平台。TensorFlow 提供了非常丰富的深度学习相关的 API,可以说目前所有深度学习框架里,提供的 API 最全的,包括基本的向量矩阵计算、各种优化算法、各种卷积神经网络和循环神经网络基本单元的实现、以及可视化的辅助工具、等等。
基于 TensorFlow 的 API 是可以做其它语言绑定的,目前只有 Python 语言绑定是谷歌公司官方推荐和支持的,实现的功能也是最权威最完整的。除了对 Python 的大力支持外,其它语言的绑定就显得非常弱小,几乎不能用。TensorFlow.NET 是用 C# 语言对 TensorFlow API 进行绑定,并最大化保持 Python 的接口使用习惯,让其它模型代码能快速的迁移到 .NET。
v0.3.0 主要是新增了一个图像识别的示例程序和修复一些 Bug。具体代码可以参考 TensorFlowNET.Examples 的 LabelImage 的样例。
private NDArray ReadTensorFromImageFile (string file_name,
int input_height = 299,
int input_width = 299,
int input_mean = 0,
int input_std = 255)
{
return with<Graph, NDArray>(tf.Graph () .as_default (), graph =>
{
var file_reader = tf.read_file (file_name, "file_reader");
var image_reader = tf.image.decode_jpeg (file_reader, channels: 3, name: "jpeg_reader");
var caster = tf.cast (image_reader, tf.float32);
var dims_expander = tf.expand_dims (caster, 0);
var resize = tf.constant (new int[] { input_height, input_width });
var bilinear = tf.image.resize_bilinear (dims_expander, resize);
var sub = tf.subtract (bilinear, new float[] { input_mean });
var normalized = tf.divide (sub, new float[] { input_std });
return with<Session, NDArray>(tf.Session (graph), sess => sess.run (normalized));
});
}
-
2/18/2019 2:49:18 AM Starting LabelImage
label_image_data\inception_v3_2016_08_28_frozen.pb.tar.gz already exists.
label_image_data\grace_hopper.jpg already exists.
2019-02-18 20:49:19.499758: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
create_op: Const 'file_reader/filename', inputs: empty, control_inputs: empty, outputs: file_reader/filename:0
create_op: ReadFile 'file_reader', inputs: file_reader/filename:0, control_inputs: empty, outputs: file_reader:0
create_op: DecodeJpeg 'jpeg_reader', inputs: file_reader:0, control_inputs: empty, outputs: jpeg_reader:0
create_op: Cast 'Cast/Cast', inputs: jpeg_reader:0, control_inputs: empty, outputs: Cast/Cast:0
create_op: Const 'ExpandDims/dim', inputs: empty, control_inputs: empty, outputs: ExpandDims/dim:0
create_op: ExpandDims 'ExpandDims', inputs: Cast/Cast:0, ExpandDims/dim:0, control_inputs: empty, outputs: ExpandDims:0
create_op: Const 'Const', inputs: empty, control_inputs: empty, outputs: Const:0
create_op: ResizeBilinear 'ResizeBilinear', inputs: ExpandDims:0, Const:0, control_inputs: empty, outputs: ResizeBilinear:0
create_op: Const 'y', inputs: empty, control_inputs: empty, outputs: y:0
create_op: Sub 'Sub', inputs: ResizeBilinear:0, y:0, control_inputs: empty, outputs: Sub:0
create_op: Const 'y_1', inputs: empty, control_inputs: empty, outputs: y_1:0
create_op: RealDiv 'truediv', inputs: Sub:0, y_1:0, control_inputs: empty, outputs: truediv:0
grace_hopper.jpg: 653 military uniform, 0.8343058
grace_hopper.jpg: 668 mortarboard, 0.02186947
grace_hopper.jpg: 401 academic gown, 0.01035806
grace_hopper.jpg: 716 pickelhaube, 0.008008132
grace_hopper.jpg: 466 bulletproof vest, 0.005350832
2/19/2019 2:49:26 AM Completed LabelImage
文档地址:Document
仓库地址:Github
聊天室:Gitter
软件下载地址:NuGet