繁体   English   中英

Keras tensorflow后端不检测GPU

[英]Keras tensorflow backend does not detect GPU

我在linux上使用tensorflow后端运行keras。 首先,我自己安装了tensorflow GPU版本,并运行以下代码进行检查,发现它在GPU上运行并显示正在运行的GPU,设备映射等。我使用的张量流来自https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow- 0.11.0-cp27-none-linux_x86_64.whl

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 我检查了conda list ,现在我有两个版本的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吗? 如果问题是由于张量流没有检测到GPU,我该如何解决这个问题? 我在这个链接中读到它表示tensorflow将自动在GPU上运行它是否检测到一个。

有可能Keras,取决于更新版本的TensorFlow,导致安装仅CPU的TensorFlow软件包( tensorflow ),该软件包隐藏了旧版GPU( tensorflow-gpu )。

我会首先升级支持GPU的版本。 通常你可以只做pip install --upgrade tensorflow-gpu ,但你在TensorFlow安装页面中有Anaconda特定的指令。 然后,您可以使用pip uninstall tensorflow仅CPU的TensorFlow软件包。 现在import tensorflow as tf实际上应该导入支持GPU的包,正如你的建议,它应该自动检测你的GPU。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM