tensorflow-gpu的几个坑
- 940mx显卡:cuda8+cudnn5
- 1050:cuda8安装选自定义安装,仅仅选择cuda即可,cudnn6
- 配置cudnn路径变量
- vs2017不支持,仅仅支持2013,2015
- 安装tensorflow之前需要配置:C:\Windows\System32\msvcp140.dll环境变量
- 参考1 参考2
- vs2015地址
你的第一个Grpah & run it in a session
在开始之前不妨先了解下特你tensorflow的一些基本概念:中文社区,当然如果你已经了解,跳过。
A TensorFlow program is typically split into two parts:
the first part builds a computation graph (this is called the construction phase)
the second part runs it (this is the execution phase). The construction phase typically builds a computation graph representing the ML model and the computations required to train it. The execution phase generally runs a loop that evaluates a training step repeatedly (for example, one step per mini-batch), gradually improving the model parameters.
# encoding: utf-8
"""
@version: python3.5.2
@author: kaenlee @contact: lichaolfm@163.com
@software: PyCharm Community Edition
@time: 2017/8/3 10:01
purpose:
"""
import tensorflow as tf
# creates a computation graph
x = tf.Variable(3, name="x")
y = tf.Variable(4, name='y')
f = tf.add(tf.multiply(tf.multiply(x, x), y), tf.add(y, 2)) #多个op组合成一个op
#The following code creates a session, initializes the variables,
sess = tf.Session()
initial = tf.global_variables_initializer()
sess.run(initial)
#evaluates, and f then closes the session
result = sess.run(f)
print(result)
sess.close()
# 另外一种写法
with tf.Session() as sess:
x.initializer.run()
y.initializer.run()
res = sess.run(f)
print(res)
sess.close()