1. 程式人生 > >VS2017+python3.6+Tensorflow環境搭建

VS2017+python3.6+Tensorflow環境搭建

第一步:

安裝VS2017(參考Opencv那一篇部落格),勾選Python選項

第二步:

配置環境變數


第三步:

用管理員開啟Power shell

輸入:pip3 install --upgrade tensorflow

第四步:

驗證是否成功

新建python程式

輸入程式碼:

#coding:utf-8 
import tensorflow as tf
w1 = tf.Variable(tf.random_normal([2,3],stddev=1,seed=1))
w2 = tf.Variable(tf.random_normal([3,1],stddev=1,seed=1))
x = tf.constant([[0.7,0.9]])
a = tf.matmul(x,w1)
y = tf.matmul(a,w2)
sess = tf.Session()
init_op = tf.initialize_all_variables()
sess.run(init_op)
print(sess.run(y))
sess.close()

執行結果:


(其中的提示是因為沒有正對CPU進行優化,需要編譯tensorflow才可以,後期送上解決教程)