tensorflow - 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却不能。我已经处理这个问题很多天了,它让我发疯。请帮帮我。
解决方案
您尝试做的事情毫无意义,TensorFlow 不支持 Intel GPU,仅支持 NVIDIA CUDA GPU,您的 Intel GPU 在 TensorFlow 中不可用,因此它始终只能看到一个 GPU。
要使用多 GPU,您至少需要 2 个 NVIDIA CUDA GPU。
推荐阅读
- sql - 在 Excel 密码保护的工作表上运行 SQL。连接问题
- reinforcement-learning - Ray RLllib:供外部使用的出口政策
- r - ggplot中传说中的希腊字母
- wordpress - 如何让一个静态 HTML 文件正常访问,不让 WordPress 运行?
- c++ - 使用 boost asio 时出现“解决:找不到主机(权威)”异常
- scala - Spark:无法将此数组转换为不安全的格式,因为它太大了
- python - 通过 python 将视频上传到 youtube
- java - Libgdx 在 Fedora 31 上不起作用 - 无法初始化类 org.lwjgl.Sys
- typescript - 枚举/类型/字符串作为对象类型/接口中的键
- apache-kafka - Kafka 代理正常关闭,错误的元数据被传递到 Kafka 连接客户端