2017-06-29 136 views
9

我已經aldready花了相當的時間對堆棧溢出周圍挖掘和其他尋找答案,但找不到任何Tensorflow不是在GPU上運行

大家好,

我我在上面運行Keras的Tensorflow。 我90%確定我安裝了Tensorflow GPU,有沒有什麼方法可以檢查我做了哪些安裝?

我試圖從Jupyter筆記本上運行一些CNN模型,我注意到Keras在CPU上運行模型(選中的任務管理器,CPU處於100%)。

我試圖從tensorflow網站運行此代碼:

# Creates a graph. 
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') 
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') 
c = tf.matmul(a, b) 
# Creates a session with log_device_placement set to True. 
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 
# Runs the op. 
print(sess.run(c)) 

這是我得到:

MatMul: (MatMul): /job:localhost/replica:0/task:0/cpu:0 
2017-06-29 17:09:38.783183: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] MatMul: (MatMul)/job:localhost/replica:0/task:0/cpu:0 
b: (Const): /job:localhost/replica:0/task:0/cpu:0 
2017-06-29 17:09:38.784779: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] b: (Const)/job:localhost/replica:0/task:0/cpu:0 
a: (Const): /job:localhost/replica:0/task:0/cpu:0 
2017-06-29 17:09:38.786128: I c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] a: (Const)/job:localhost/replica:0/task:0/cpu:0 
[[ 22. 28.] 
[ 49. 64.]] 

這對我顯示我正在我的CPU上,出於某種原因。

我有一個GTX1050(驅動程序版本382.53),我安裝了CUDA,並且Cudnn和tensorflow安裝沒有任何問題。我也安裝了Visual Studio 2015,因爲它被列爲兼容版本。

我記得CUDA提到一些關於安裝不兼容驅動程序的內容,但是如果我正確地記得CUDA應該安裝它自己的驅動程序。

編輯: 我跑論文命令列出可用的設備

from tensorflow.python.client import device_lib 
print(device_lib.list_local_devices()) 

,這就是我得到

[name: "/cpu:0" 
device_type: "CPU" 
memory_limit: 268435456 
locality { 
} 
incarnation: 14922788031522107450 
] 

和一大堆警告這樣

2017-06-29 17:32:45.401429: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations. 

編輯2

試圖運行

pip3 install --upgrade tensorflow-gpu 

,我得到

Requirement already up-to-date: tensorflow-gpu in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages 
Requirement already up-to-date: markdown==2.2.0 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: html5lib==0.9999999 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: werkzeug>=0.11.10 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: wheel>=0.26 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: bleach==1.5.0 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: six>=1.10.0 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: protobuf>=3.2.0 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: backports.weakref==1.0rc1 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: numpy>=1.11.0 in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from tensorflow-gpu) 
Requirement already up-to-date: setuptools in c:\users\goofynose\appdata\local\programs\python\python35\lib\site-packages (from protobuf>=3.2.0->tensorflow-gpu) 

解決: 爲解決檢查意見。 感謝所有幫助!

我對此很陌生,所以任何幫助,非常感謝! 謝謝。

+0

兼容的版本,是否安裝TF與PIP ? – danche

+0

您可以使用https://stackoverflow.com/documentation/tensorflow/10621/tensorflow-gpu-setup/31878/list-the-available-devices-available-by-tensorflow-in-the-local列出可用設備-process#t = 201706291527588861941? – npf

+0

是的,我使用pip3安裝了Tensorflow,我正在運行Python 3. – Goofynose

回答

8

要檢查哪些設備可用來TensorFlow你可以使用這個,看看GPU卡可用:

from tensorflow.python.client import device_lib 
print(device_lib.list_local_devices()) 

編輯 另外,如果你使用TensorFlow Cuda的版本,你會看到這樣的日誌:

I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so.*.* locally 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so.*.* locally 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so.*.* locally 
+0

將它作爲編輯添加到問題中 – Goofynose

2

即使通過pip正確安裝tensorflow-gpu,我仍然無法獲得GPU支持。我的問題是我安裝了tensorflow 1.5和CUDA 9.1(Nvidia的默認版本),而預編譯的tensorflow 1.5適用於CUDA版本< = 9.0。這裏是NVIDIA的網站下載頁面,以獲得正確的CUDA 9.0:

https://developer.nvidia.com/cuda-90-download-archive

同時一定要更新您的cuDNN與CUDA 9.0 https://developer.nvidia.com/cudnn https://developer.nvidia.com/rdp/cudnn-download