首页 > 解决方案 > keras检测不到gpu

问题描述

我的 keras-gpu 有问题。

我用 Anaconda 安装 keras-gpu。我的笔记本电脑有两个 gpu。一个是nVidia GTX950M,另一个是Intel集成显卡。当我运行这些测试代码时,

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

控制台显示:

2019-01-19 09:34:15.794202: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2019-01-19 09:34:16.303681: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties:
name: GeForce GTX 950M major: 5 minor: 0 memoryClockRate(GHz): 1.124
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.65GiB
2019-01-19 09:34:16.310913: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0
2019-01-19 09:34:17.879659: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-01-19 09:34:17.884168: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971]      0
2019-01-19 09:34:17.886646: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0:   N
2019-01-19 09:34:17.890046: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1400 MB memory) -> physical GPU (device: 0, name: GeForce GTX 950M, pci bus id: 0000:01:00.0, compute capability: 5.0)
b'Hello, TensorFlow!'

看来我的 nVidia gpu 正在工作。但我使用我的 keras-gpu,并运行以下代码。

x_train,y_train = dataGenerate()
model = Sequential()
model.add(Dense(units=1,input_dim=1))
model.add(Dense(units=5))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('relu'))
model.add(Dense(units=5))
model.add(Activation('relu'))
model.add(Dense(units=1))

model = multi_gpu_model(model, 2)
model.summary()
model.compile(loss='mean_squared_error',optimizer = 'sgd')

history = model.fit(x_train,y_train,epochs=200,batch_size=10)

我检查了任务管理器,只有我的英特尔集成显卡工作。我努力了

os.environ["CUDA_VISIBLE_DEVICES"]="1"

但它仍然无法正常工作。我试图将这些行添加到我的代码中,

model = multi_gpu_model(model, 2)
model.summary()

控制台显示:

ValueError: To call `multi_gpu_model` with `gpus=2`, 
we expect the following devices to be available: ['/cpu:0', '/gpu:0', '/gpu:1']. 
However this machine only has: ['/cpu:0', '/gpu:0']. Try reducing `gpus`.

gpu0 是我的英特尔显卡。所以事实证明我的 keras-gpu 无法检测到我的 nvidia gpu。这没有意义。我的tensorflow怎么能检测到gpu,而keras却不能。我已经处理这个问题很多天了,它让我发疯。请帮帮我。

标签: tensorflowkerasgpunvidia

解决方案


您尝试做的事情毫无意义,TensorFlow 不支持 Intel GPU,仅支持 NVIDIA CUDA GPU,您的 Intel GPU 在 TensorFlow 中不可用,因此它始终只能看到一个 GPU。

要使用多 GPU,您至少需要 2 个 NVIDIA CUDA GPU。


推荐阅读