tensorflow-gpu的幾個坑
- 940mx顯卡:cuda8+cudnn5
- 1050:cuda8安裝選自定義安裝,僅僅選擇cuda即可,cudnn6
- 配置cudnn路徑變量
- vs2017不支持,僅僅支持2013,2015
- 安裝tensorflow之前需要配置:C:\Windows\System32\msvcp140.dll環(huán)境變量
- 參考1 參考2
- vs2015地址
你的第一個Grpah & run it in a session

在開始之前不妨先了解下特你tensorflow的一些基本概念:中文社區(qū),當然如果你已經了解,跳過。
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()