为了账号安全,请及时绑定邮箱和手机立即绑定

如何知道 Keras 使用的是 GPU 还是 CPU

如何知道 Keras 使用的是 GPU 还是 CPU

qq_笑_17 2023-05-23 15:38:05
有什么方法可以检查 Keras 框架是使用 GPU 还是 CPU 来训练模型?我正在使用 keras 在 GPU 上训练我的模型,但它太慢了,我不确定它是使用 CPU 还是 GPU 进行训练。
查看完整描述

3 回答

?
红颜莎娜

TA贡献1842条经验 获得超12个赞

首先,您需要找到 GPU 设备:

physical_device = tf.config.experimental.list_physical_devices('GPU')
print(f'Device found : {physical_device}')

然后您可以使用以下代码检查您的 GPU 设备是否已用于训练:

tf.config.experimental.get_memory_growth(physical_device[0])

如果此代码返回False或什么都没有,那么您可以运行下面的代码来设置 GPU 进行训练

tf.config.experimental.set_memory_growth(physical_device[0],True)


查看完整回答
反对 回复 2023-05-23
?
沧海一幻觉

TA贡献1824条经验 获得超5个赞

首先让我们确保 tensorflow 正在检测您的 GPU。运行下面的代码。如果 GPU 数量=0,则表示未检测到您的 GPU。要让 tensorflow 使用 GPU,您需要安装 Cuda 工具包和 Cudnn。如果未检测到 GPU 并且您正在使用 Anaconda,请使用 Conda 重新安装 tensorflow。它会自动安装工具包和 Cudnn。当您使用它来安装 tensorflow 时,pip 不会安装这些。


import tensorflow as tf

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())

print(tf.__version__)

print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

tf.test.is_gpu_available()

!python --version


查看完整回答
反对 回复 2023-05-23
?
繁星coding

TA贡献1797条经验 获得超4个赞

这是参考演示:


import tensorflow as tf

physical_device = tf.config.experimental.list_physical_devices('GPU')

print(f'Device found : {physical_device}') 


查看完整回答
反对 回复 2023-05-23
  • 3 回答
  • 0 关注
  • 318 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信