[英]Keras Machine Learning Code are not using GPU
我正在使用keras和tensorflow作为后端。 我连接到带有两个GPU(1080ti)的服务器。 但是,当我运行代码时。我的代码只是忽略了我强大的资源。 这是一些信息
$ nvidia-smi在运行代码时:
我的GPU信息之一:
我确实在版本1.9.0中安装了tensorflow-gpu
$ pip show tensorflow-gpu:
看来它可以成功检测到我的GPU。
所以有什么问题?
keras倾向于安装tensorflow-cpu。
检查tensorflow-cpu的点列表并删除它。 您也可以运行以下代码来尝试强制TF使用GPU。
def get_available_devices():
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos]
get_available_devices()
with tf.device('/gpu:0'):
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)
with tf.Session() as sess:
print (sess.run(c))
您可以通过Tensorflow指定正在运行的设备:
model = keras.models.Sequential()
model.add(...)
model.compile(...)
with tensorflow.device('/device:GPU:0'):
model_wc.fit(X_train, y_train, validation_data=(X_test, y_test), ...)
model_wc.evaluate(X_test, y_test)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.