2017-07-18 201 views
1

我在linux上運行tensorflow後端keras。 首先,我本身安裝tensorflow GPU版本,運行下面的代碼檢查,並發現它是在GPU上運行,並顯示它的運行在GPU上,設備映射,等我用tensorflow來自https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow- 0.11.0-cp27-none-linux_x86_64.whlKeras tensorflow後端檢測不到GPU

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)) 

然後,我使用conda install keras安裝了keras。我檢查了conda list,現在我有2個版本的tensorflow(1.1.0和0.11.0)。我試圖import tensorflow as tf導致:

2017-07-18 16:35:59.569535: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 
2017-07-18 16:35:59.569629: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 
2017-07-18 16:35:59.569690: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 
2017-07-18 16:35:59.569707: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 
2017-07-18 16:35:59.569731: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 
Device mapping: no known devices. 
2017-07-18 16:35:59.579959: I tensorflow/core/common_runtime/direct_session.cc:257] Device mapping: 

MatMul: (MatMul): /job:localhost/replica:0/task:0/cpu:0 
2017-07-18 16:36:14.369948: I tensorflow/core/common_runtime/simple_placer.cc:841] MatMul: (MatMul)/job:localhost/replica:0/task:0/cpu:0 
b: (Const): /job:localhost/replica:0/task:0/cpu:0 
2017-07-18 16:36:14.370051: I tensorflow/core/common_runtime/simple_placer.cc:841] b: (Const)/job:localhost/replica:0/task:0/cpu:0 
a: (Const): /job:localhost/replica:0/task:0/cpu:0 
2017-07-18 16:36:14.370109: I tensorflow/core/common_runtime/simple_placer.cc:841] a: (Const)/job:localhost/replica:0/task:0/cpu:0 

我已經設置CUDA_VISIBLE_DEVICES,安裝keras之前其工作。 這是因爲tensorflow的版本?安裝keras時,我可以選擇安裝0.11.0而不是1.1.0嗎? 如果問題是由於tensorflow沒有檢測到GPU,我該如何解決這個問題?我讀了link,它說tensorflow會自動運行在GPU上,它會檢測到一個。

+0

我能夠通過'pip install tensorflow-gpu'再次安裝tensorflow來解決問題。來自keras GitHub的問題:https://github.com/fchollet/keras/issues/5712。 – matchifang

回答

2

根據更新版本的TensorFlow,Keras可能會導致安裝僅支持CPU的TensorFlow軟件包(tensorflow),該軟件包隱藏了舊版支持GPU的版本(tensorflow-gpu)。

我會先升級支持GPU的版本。通常你可以做pip install --upgrade tensorflow-gpu,但是你在TensorFlow installation page中有特定於Anaconda的說明。然後,您可以使用pip uninstall tensorflow卸載僅限CPU的TensorFlow軟件包。現在import tensorflow as tf應該實際導入啓用GPU的軟件包,如您所建議的那樣,它應該會自動檢測您的GPU。

相關問題