我可以在 GPU 上运行 Keras 模型吗? [英] Can I run Keras model on gpu?

查看:33
本文介绍了我可以在 GPU 上运行 Keras 模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 Keras 模型,提交截止日期为 36 小时,如果我在 cpu 上训练我的模型大约需要 50 小时,有没有办法在 gpu 上运行 Keras?

我正在使用 Tensorflow 后端并在我的 Jupyter 笔记本上运行它,但没有安装 anaconda.

解决方案

是的,您可以在 GPU 上运行 keras 模型.您必须先检查几件事.

  1. 您的系统有 GPU(Nvidia.由于 AMD 尚不可用)
  2. 您已经安装了 GPU 版本的 tensorflow
  3. 您已安装 CUDA 安装说明
  4. 验证 tensorflow 是否与 GPU 一起运行 检查 GPU 是否正常工作

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

对于 TF >v2.0

sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))

(感谢@nbro 和@Ferro 在评论中指出这一点)

from tensorflow.python.client import device_lib打印(device_lib.list_local_devices())

输出将是这样的:

<预><代码>[名称:/cpu:0"设备类型:CPU",名称:/gpu:0"设备类型:GPU"]

完成所有这些后,您的模型将在 GPU 上运行:

要检查 keras(>=2.1.1) 是否正在使用 GPU:

from keras import backend as KK.tensorflow_backend._get_available_gpus()

一切顺利.

I'm running a Keras model, with a submission deadline of 36 hours, if I train my model on the cpu it will take approx 50 hours, is there a way to run Keras on gpu?

I'm using Tensorflow backend and running it on my Jupyter notebook, without anaconda installed.

解决方案

Yes you can run keras models on GPU. Few things you will have to check first.

  1. your system has GPU (Nvidia. As AMD doesn't work yet)
  2. You have installed the GPU version of tensorflow
  3. You have installed CUDA installation instructions
  4. Verify that tensorflow is running with GPU check if GPU is working

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

for TF > v2.0

sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))

(Thanks @nbro and @Ferro for pointing this out in the comments)

OR

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

output will be something like this:

[
  name: "/cpu:0"device_type: "CPU",
  name: "/gpu:0"device_type: "GPU"
]

Once all this is done your model will run on GPU:

To Check if keras(>=2.1.1) is using GPU:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()

All the best.

这篇关于我可以在 GPU 上运行 Keras 模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆