Keras Tensorflow后端未检测到GPU [英] Keras tensorflow backend does not detect GPU

查看:742
本文介绍了Keras Tensorflow后端未检测到GPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running keras with tensorflow backend on linux. First, I installed tensorflow GPU version by itself, and run the following code to check and found out that it's running on GPU and shows the GPU it's running on, device mapping, etc. The tensorflow I use was from 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安装了keras.我检查了conda list,现在我有2个版本的tensorflow(1.1.0和0.11.0).我尝试了import tensorflow as tf,结果是:

Then, I installed keras using conda install keras. I checked conda list and now I have 2 versions of tensorflow (1.1.0 and 0.11.0). I tried import tensorflow as tf which results in:

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,我该如何解决此问题?我在此链接中进行了阅读它说tensorflow会在检测到一个时自动在GPU上运行.

I already set CUDA_VISIBLE_DEVICES, which works before keras was installed. Is this because of the tensorflow version? Can I choose to install 0.11.0 instead of 1.1.0 when installing keras? If the problem is due to tensorflow not detecting a GPU, how can I solve this issue? I read in this link and it says that tensorflow will automatically run on GPU is it detects one.

推荐答案

可能是Keras(取决于TensorFlow的较新版本)导致安装了仅CPU的TensorFlow软件包(tensorflow),该软件包隐藏了较早的,启用GPU的版本(tensorflow-gpu).

Chances are that Keras, depending on a newer version of TensorFlow, has caused the installation of a CPU-only TensorFlow package (tensorflow) that is hiding the older, GPU-enabled version (tensorflow-gpu).

我将首先升级支持GPU的版本.通常,您只能执行pip install --upgrade tensorflow-gpu,但是 TensorFlow安装页面.然后,您可以使用pip uninstall tensorflow卸载仅CPU的TensorFlow软件包.现在import tensorflow as tf实际上应该导入支持GPU的程序包,如您建议的那样,该程序包又应自动检测您的GPU.

I would upgrade the GPU-enabled version first. Usually you can just do pip install --upgrade tensorflow-gpu, but you have Anaconda-specific instructions in the TensorFlow installation page. Then you can uninstall the CPU-only TensorFlow package with pip uninstall tensorflow. Now import tensorflow as tf should actually import the GPU-enabled package which, as you suggest, should in turn detect your GPU automatically.

这篇关于Keras Tensorflow后端未检测到GPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆