2.0兼容答案 :虽然上述答案详细说明了如何在Keras Model上使用GPU,但我想说明如何在Tensorflow Version 2.0
。
要知道有多少个GPU可用,我们可以使用以下代码:
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
要找出您的操作和张量分配给哪些设备,请将tf.debugging.set_log_device_placement(True)
作为程序的第一条语句。
启用设备放置日志记录将导致打印任何张量分配或操作。例如,运行以下代码:
tf.debugging.set_log_device_placement(True)
# Create some tensors
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)
给出如下所示的输出:
在设备/ job:localhost / replica:0 / task:0 / device:GPU:0 tf.Tensor([[22. 28.] [49. 64.]],shape =(2,2),中执行op MatMul dtype = float32)
有关更多信息,请参考此链接
0
我正在运行Keras模型,提交截止日期为36小时,如果我在cpu上训练我的模型大约需要50个小时,是否可以在gpu上运行Keras?
我正在使用Tensorflow后端并在未安装anaconda的Jupyter笔记本上运行它。