【问题标题】:Regarding Keras Tensorflow backend GPU关于 Keras TensorFlow 后端 GPU
【发布时间】:2018-07-18 12:52:42
【问题描述】:

我正在尝试在 GPU 上运行 LSTM 代码。我已将 keras 后端设置为 tensorflow。我知道 tensorflow 会自动在 GPU 上运行。但是我仍在添加以下行以使其在 GPU 上运行。有没有其他方法可以确认它正在使用 GPU?我是这个学习的新手,所以你的建议对我很有帮助。

import os
os.environ['CUDA_DEVICE_ORDER']='PCI_BUS_ID'
os.environ['CUDA_VISIBLE_DEVICES'] = "0"

要禁用/屏蔽 GPU/强制使其在 CPU 上运行,我这样做:

os.environ['CUDA_VISIBLE_DEVICES'] = " "

可用的设备是:

from tensorflow.python.client import device_lib

device_lib.list_local_devices()

Out[2]: 
[name: "/cpu:0"
 device_type: "CPU"
 memory_limit: 268435456
 locality {
 }
 incarnation: 629258381829369248, name: "/gpu:0"
 device_type: "GPU"
 memory_limit: 324403200
 locality {
   bus_id: 1
 }
 incarnation: 7545755248924255940
 physical_device_desc: "device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0"]

【问题讨论】:

标签: tensorflow keras gpu


【解决方案1】:

是的,您的 Tensorflow 后端使用 GPU,device_lib.list_local_devices() 证实了这一点。

但是,请注意使用list_local_devices() 的副作用。它为 Tensorflow 分配 GPU 上的所有内存。如果您打算一次使用 GPU 运行多个脚本,那可能会搞砸。

以下是这方面的详细信息:#9374#8021

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 2020-06-13
    • 2018-02-15
    • 2021-11-28
    • 1970-01-01
    • 2018-10-02
    • 2023-03-14
    • 1970-01-01
    • 2018-09-26
    相关资源
    最近更新 更多