TensorFlow没有在GPU上运行(带有TF后端的keras)

时间:2018-04-17 01:58:28

标签: python tensorflow machine-learning keras gpu

我已按照installing tensorflow with GPU support上的步骤操作,并确保我使用的机器具有兼容的GPU,但似乎TensorFlow仍然无法在我的机器上正常运行。我有一个程序,使用TensorFlow后端训练keras顺序模型(使用python 2.7)和输出,同时训练输出如下:



2018-04-17 00:35:13.837040: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-04-17 00:35:14.042784: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-04-17 00:35:14.043143: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1344] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:00:1e.0
totalMemory: 11.17GiB freeMemory: 11.10GiB
2018-04-17 00:35:14.043186: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1423] Adding visible gpu devices: 0
2018-04-17 00:35:16.374355: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-04-17 00:35:16.374397: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917]      0 
2018-04-17 00:35:16.374405: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0:   N 
2018-04-17 00:35:16.380956: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10764 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7)




我真的不明白这些日志的意思,但是,我在一台只有CPU的设备上同时运行这项工作,完成培训工作所花费的时间是相同的。任何人都可以帮我告诉我如何让我的训练工作在GPU上运行?提前谢谢!

1 个答案:

答案 0 :(得分:0)

您可能会考虑尝试指定GPU来运行程序,这是一段简单的代码。

with tf.device('/gpu:1'):
  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)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print sess.run(c)

如果没有,我建议使用anaconda3创建TensorFlow-GPU虚拟环境,通常默认为GPU版本。