我可以在 GPU 上运行 Keras 模型吗?

编程入门 行业动态 更新时间:2024-10-26 12:26:50
本文介绍了我可以在 GPU 上运行 Keras 模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

解决方案

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

  • 您的系统有 GPU(Nvidia.由于 AMD 尚不可用)
  • 您已经安装了 GPU 版本的 tensorflow
  • 您已安装 CUDA 安装说明
  • 验证 tensorflow 是否与 GPU 一起运行 检查 GPU 是否正常工作
  • sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

    对于 TF >v2.0

    sess = tfpat.v1.Session(config=tfpat.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.

  • your system has GPU (Nvidia. As AMD doesn't work yet)
  • You have installed the GPU version of tensorflow
  • You have installed CUDA installation instructions
  • 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 = tfpat.v1.Session(config=tfpat.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 模型吗?

    本文发布于:2023-06-01 10:30:49,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/413011.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:模型   GPU   Keras

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!