TensorFlowSharp入门使用C#编写TensorFlow人工智能应用学习

文章末尾博主为大家整理了人工智能学习资料有想提升自身能力和转行的朋友可以免费领取。

历史优秀文章推荐:

人工智能图像识别深度解析:弱人工智能时代最重要的一个应用

AI人士不得不了解的十大机器算法

一文看懂自然语言处理-NLP(4个典型应用+5个难点+6个实现步骤)

TensorFlow简单介绍
TensorFlow 是谷歌的第二代机器学习系统,按照谷歌所说,在某些基准测试中,TensorFlow的表现比第一代的DistBelief快了2倍。

TensorFlow 内建深度学习的扩展支持,任何能够用计算流图形来表达的计算,都可以使用TensorFlow。任何基于梯度的机器学习算法都能够受益于TensorFlow的自动分化(auto-differentiation)。通过灵活的Python接口,要在TensorFlow中表达想法也会很容易。

TensorFlow 对于实际的产品也是很有意义的。将思路从桌面GPU训练无缝搬迁到手机中运行。

示例Python代码:

import tensorflow as tf
import numpy as np
 
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3
 
# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b
 
# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
 
# Before starting, initialize the variables.  We will 'run' this first.
init = tf.global_variables_initializer()
 
# Launch the graph.
sess = tf.Session()
sess.run(init)
 
# Fit the line.
for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))
 
# Learns best fit is W: [0.1], b: [0.3]
使用TensorFlowSharp 
GitHub:https://github.com/migueldeicaza/TensorFlowSharp

官方源码库,该项目支持跨平台,使用Mono。

可以使用NuGet 安装TensorFlowSharp,如下:

Install-Package TensorFlowSharp
编写简单应用
使用VS2017新建一个.NET Framework 控制台应用 tensorflowdemo,接着添加TensorFlowSharp 引用。

TensorFlowSharp 包比较大,需要耐心等待。

然后在项目属性中生成->平台目标 改为 x64。

打开Program.cs 写入如下代码:

static void Main(string[] args)
        { <

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值