Win10+VS2017+Python3.6.5+Tensorflow1.9安装

1、安装VS2017,选择安装Anaconda3(64bit)支持

2、下载tensorflow‑1.9.0‑cp36‑cp36m‑win_amd64.whl到桌面(网址https://www.lfd.uci.edu/~gohlke/pythonlibs/

3、打开Anaconda Prompt,cd到桌面,输入pip install tensorflow‑1.9.0‑cp36‑cp36m‑win_amd64.whl(联网自动安装依赖项)

4、完成后测试如下:

import numpy as np
import tensorflow as tf

# Model parameters
W = tf.Variable([.3], dtype=tf.float32)
b = tf.Variable([-.3], dtype=tf.float32)
# Model input and output
x = tf.placeholder(tf.float32)
linear_model = W * x + b
y = tf.placeholder(tf.float32)
# loss
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares

# optimizer,定义一个优化器,使用梯度下降优化方法
optimizer = tf.train.GradientDescentOptimizer(0.01)
#优化器最小化loss
train = optimizer.minimize(loss)

# training data
x_train = [1,2,3,4]
y_train = [0,-1,-2,-3]

# training loop
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong

#迭代一千次后,参数已经训练好
for i in range(1000):
  sess.run(train, {x:x_train, y:y_train})

#送入训练好的参数,求出loss
# evaluate training accuracy
curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x:x_train, y:y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))

5、结果:W:[-0.9999969] b:[0.9999908] loss:5.6999738e-11

注:如果anaconda为独立安装,应按照上面步骤安装tensorflow,VS2017新建Python应用后,如果numpy等库无法检测到,请检查工具->Python->Python环境,检查是否为安装tensorflow的anaconda环境

 

如果不是,则在Python环境中按下图1~3步骤添加Anaconda3,然后在解决方案中Python环境中选择Anaconda3

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值