折騰了一天半終於裝好了win10下的TensorFlow-GPU版,在這里做個記錄。
准備安裝包:
visual studio 2015;
Anaconda3-4.2.0-Windows-x86_64;
CUDA:cuda_8.0.61_win10;下載時選擇 exe(local)
CUDA補丁:cuda_8.0.61.2_windows;
cuDNN:cudnn-8.0-windows10-x64-v6.0;如果你安裝的TensorFlow版本和我一樣1.3,請下載cuDNN v6.0 for CUDA 8.0 (不要問我為什么知道....)
開始:
1.安裝visual studio2015 可以只安裝 Visualc++部分
2.安裝CUDA:
按提示安裝,先安裝cuda_8,再安裝補丁;
裝完后在cmd里查看版本號:nvcc -V
3.安裝cuDNN庫:
把解壓文件放置到CUDA的相關文件夾里:(懶得打字了)
==============》》
4.安裝Anaconda:
我是選擇用Anaconda安裝TensorFlow,方便管理各種環境。
下載對應安裝包,按提示安裝。
裝好后,打開Anaconda Prompt.添加清華的鏡像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes
在win下更改Python的默認源為清華源:
在當前的用戶目錄下新建pip文件夾,在pip文件夾里新建pip.ini文件:
[global] index-url = http://mirrors.aliyun.com/pypi/simple/ //https://pypi.tuna.tsinghua.edu.cn/simple 清華源 [install] trusted-host=mirrors.aliyun.com
在Anaconda里建立TensorFlow的環境:
conda create -n tensorflow Python=3.5
激活TensorFlow環境:
activate TensorFlow
關閉環境:
deactivate
5.安裝TensorFlow:
pip install --upgrade --ignore-installed tensorflow-gpu
安裝TensorFlow指定版本(清華源上有的,更換鏈接最后的版本名稱就行了)
pip install --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/gpu/tensorflow_gpu-1.3.0rc0-cp35-cp35m-win_amd64.whl
簡單測試:
在TensorFlow環境里打開Python:
import tensorflow as tf hello = tf.constant("Hello!TensorFlow") sess = tf.Session() print(sess.run(hello))
見到b'hello tensorflow' 測試成功。
6.安裝,配置pycharm:
下載對應安裝包。按提示安裝pycharm。
配置pycharm:
在選擇Python版本時,手動添加位於Anaconda的python版本,位置在Anaconda的安裝目錄下的envs文件夾里:
7.在pycharm里新建mnist手寫識別程序:
from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/",one_hot=True) import tensorflow as tf sess = tf.InteractiveSession() x = tf.placeholder(tf.float32,[None,784]) 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) tf.global_variables_initializer().run() for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) train_step.run({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(accuracy.eval({x: mnist.test.images, y_: mnist.test.labels}))
運行:
至此全部安裝完畢。
安裝過程中的坑:
1.安裝TensorFlow1.3的cuDNN的版本要選V6的版本,不然會出現
No Module Named '_pywrap_tensorflow_internal'
以及
DLL load failed: The specified module could not be found等錯誤。