在根據教程http://blog.csdn.net/sb19931201/article/details/53648615安裝好全部的時候,卻無情的給我拋了幾個錯:
1、AttributeError: module 'tensorflow' has no attribute 'device'
這貌似是我先pip了tensorflow-gpu的包,再添加cuDnn庫。
2、ImportError: Could not find 'cudart64_80.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-toolkit
在下載的CUDA的時候,隨手下了9.0的,結果只支持8.0.。
3、ImportError: Could not find 'cudnn64_6.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 6 from this URL: https://developer.nvidia.com/cudnn
明明看教程的時候寫的是5.1版本,我也下的5.1啊,這是為什么?原來是因為我的tensorflow-gpu的版本高於1.3,所以用6.0。
4、InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'add': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: add = Add[T=DT_FLOAT, _device="/device:GPU:0"](a, b)]]
還給我彈了下面這個框
這個問題根據下面改就行。
桌面上空白地方右鍵,進入NVIDIA面板,然后下圖
選擇第二個,點擊應用,再重啟電腦即可,記得重啟電腦。
我用的以下代碼測試:
import tensorflow as tf
# # 通過tf.device將運算指定到特定的設備上。
with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0], shape=[3], name='a')
b = tf.constant([1.0, 2.0, 3.0], shape=[3], name='b')
with tf.device('/gpu:0'):
c=a+b
# 通過log_device_placement參數來記錄運行每一個運算的設備。
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))