繁体   English   中英

如何在 AWS EC2 实例上激活 GPU 的使用?

[英]How to activate the use of a GPU on AWS EC2 instance?

我正在使用 AWS 在自定义数据集上训练 CNN。 我启动了一个 p2.xlarge 实例,将我的 (Python) 脚本上传到虚拟机,然后通过 CLI 运行我的代码。

我使用 Python3(CUDA 10.0 和英特尔 MKL-DNN)激活了 TensorFlow(+Keras2) 的虚拟环境,这是 AWS 的默认选项。

我现在正在运行我的代码来训练 .network,但感觉 GPU 没有“激活”。 训练进行得和我在本地用 CPU 运行时一样快(慢)。

这是我正在运行的脚本:

https://github.com/AntonMu/TrainYourOwnYOLO/blob/master/2_Training/Train_YOLO.py

我还尝试通过在解析器(第 142 行)之后放置with tf.device('/device:GPU: 0'):并缩进下面的所有内容来更改它。 然而,这似乎并没有改变什么。

关于如何激活 GPU 的任何提示(或检查 GPU 是否已激活)?

查看此答案以列出可用的 GPU。

from tensorflow.python.client import device_lib

def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']

您还可以使用 CUDA 列出当前设备,并在必要时设置设备

import torch

print(torch.cuda.is_available())
print(torch.cuda.current_device())

最后还是和我的tensorflow package有关,只好卸载tensorflow,安装tensorflow-gpu。 之后 GPU 自动激活。

有关文档,请参阅: https://www.tensorflow.org/install/gpu

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM