本文首發(fā)在CSDN博客:http://blog.csdn.net/xxzhangx/article/details/54379255
前幾天,谷歌推出了windows對tensorflow的支持,我參考下面兩篇博文來安裝了我的tensorflow。
為表示對原創(chuàng)作者的尊敬,先列出參考的文章。
- 參考文獻
https://m.aliyun.com/yunqi/articles/68435
http://blog.csdn.net/zhuxiaoyang2000/article/details/54317206
第一步:安裝CUDNN
這里選擇的是cuda_8.0.44_win10,鏈接
為:https://developer.nvidia.com/cuda-downloads
網(wǎng)站截圖:
1.18G,下載完后,直接安裝,改為自定義方式,不用修改安裝目錄,就安裝在C盤下,方便后面的文件操作。
或去我的百度云網(wǎng)盤下載:鏈接:http://pan.baidu.com/s/1c2KdNgO 密碼:gwm1
第二步:編譯cuda
-
說明
電腦必須安裝Microsoft Visual Studio,10、12、13、15,這4個版本任意一個都可以。
VS編譯器
安裝完成后,打開Sample路徑:C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0,選擇與本機Visual Studio相對應(yīng)的Solution版本,這里選擇的是Sample_vs2015.sln。然后分別編譯Release和Debug版本。
然后漫長的等待,對Release編譯一次,然后切換到Debug下,編譯一次。圖中發(fā)現(xiàn)我的編譯在某些庫上報錯了,其原因我也不知道,但是對后面的運行暫時沒發(fā)現(xiàn)錯誤。
編譯完成后,Win+R打開命令行窗口,cd C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0\bin\win64\Release,運行deviceQuery,如果顯示如下畫面,則安裝成功。
第三步:安裝cuDNN
這里我不知道為什么要安裝,在參考文章中有說要安裝,那就根據(jù)別人成功的例子來,少踩坑。
版本號:cudnn-8.0-windows-x64-v5.1,這里可以直接用的,百度云鏈接:鏈接:http://pan.baidu.com/s/1gf9ior5 密碼:so8m
我是將cudnn中的文件直接放在目錄 C:\ProgramData\NVIDIA GPU Computing Toolkit\v8.0
第四步:安裝python
這里采用的是anaconda 4.2 python 3.5,下載網(wǎng)址:https://www.continuum.io/downloads
或者去我的百度云下載:鏈接:http://pan.baidu.com/s/1nuQqMPr 密碼:gl4h
第五步:安裝tensorflow
完全根據(jù)文章中的流程來做,鏈接https://m.aliyun.com/yunqi/articles/68435
下載完后安裝好,然后打開cmd,切換到anaconda4的scripts下:cd E:\Anaconda3\Scripts,用conda create --name tensorflow python=3.5 創(chuàng)建環(huán)境,可在env下查看參加的tensorflow環(huán)境
依次執(zhí)行下面的代碼:
activate tensorflow
conda install jupyter
conda install scipy
pip install tensorflow
注意:每次提示都選擇“y”或“是”,下載時最好能連上VPN,這樣能保證下載穩(wěn)定少出錯。
下面依次貼圖說明:
- 先激活tensorflow:
activate tensorflow
- 安裝juypter
再繼續(xù)輸入:
conda install jupyter
圖
- 安裝常用的python包,例如scipy
- 安裝tensorflow
或直接下載到本地來安裝,去https://pypi.python.org/pypi 搜索對應(yīng)的版本:
- tensorflow 非gpu: python 2.7 和 3.5
- tensorflow-gpu: python 3.5
本地安裝
在juypter下測試:
打開juypter下測試MNIST 數(shù)據(jù)集
測試代碼:
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))#結(jié)果
測試代碼截圖如下:
與官網(wǎng)https://www.tensorflow.org/versions/r0.12/tutorials/mnist/beginners/index.html結(jié)果比較:
一些可能的錯誤
歡迎補充
僅列下我遇到的問題
- 安裝過程中報錯了,再次pip install tensorflow 卻顯示已經(jīng)存在,可以用 pip uninstall tensorflow 卸載,重新pip install tensorflow 來安裝。
- 在anaconda2下安裝遇到qt[vc-14]的問題,換到anaconda3下就沒有了