我无法让 Keras 使用 GPU 版本的 Tensorflow 而不是 CPU。每次我导入 keras 时,它都会说:
>>> import keras
Using TensorFlow backend
...这意味着它正在工作,但在 CPU 上,而不是 GPU 上。我安装了 Cuda 和 cuDNN 并使用了这个环境:
conda create -n tensorflow python=3.5 anaconda
我想我首先安装了 tensorflow 的 CPU 版本——我不记得了,因为我整天都在让 cuda 和 cudnn 工作。无论如何,我也安装了 GPU 版本:
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl
它仍然给出相同的信息。我试图检查以下代码正在使用哪个设备:
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
但我得到这个输出,表明我正在使用设备 0,我的 GPU:
2017-05-12 02:14:10.746679: 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-05-12 02:14:10.746735: 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-05-12 02:14:10.746751: 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-05-12 02:14:10.746764: 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-05-12 02:14:10.746777: 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.
2017-05-12 02:14:10.926330: I
tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:901] successful
NUMA node read from SysFS had negative value (-1), but there must be
at least one NUMA node, so returning NUMA node zero
2017-05-12 02:14:10.926614: I
tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0
with properties:
name: GeForce GTX 1060 6GB
major: 6 minor: 1 memoryClockRate (GHz) 1.7845
pciBusID 0000:01:00.0
Total memory: 5.93GiB
Free memory: 5.51GiB
2017-05-12 02:14:10.926626: I
tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0
2017-05-12 02:14:10.926629: I
tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0: Y
2017-05-12 02:14:10.926637: I
tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating
TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1060 6GB,
pci bus id: 0000:01:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX
1060 6GB, pci bus id: 0000:01:00.0
2017-05-12 02:14:10.949871: I
tensorflow/core/common_runtime/direct_session.cc:257] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX
1060 6GB, pci bus id: 0000:01:00.0
我真的无事可做。我唯一剩下的就是卸载 anaconda 并重新安装所有东西,我真的不想这样做,因为我真的花了一整天时间让它与 keras 和所有东西一起工作(只是还没有使用 GPU)