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

2024-04-28 20:47:24 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我用Python3(CUDA 10.0和Intel MKL-DNN)为TensorFlow(+Keras2)激活了一个虚拟环境,这是AWS的默认选项

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

这是我正在运行的脚本:

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

我还试图通过将with tf.device('/device:GPU: 0'):放在解析器后面(第142行)并缩进下面的所有内容来修改它。然而,这似乎没有改变任何事情

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


Tags: 实例代码脚本awscligpudevicecnn
2条回答

最后,它与我的tensorflow软件包有关!我不得不卸载tensorflow并安装tensorflow gpu。之后,GPU被自动激活

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

签出this answer以列出可用的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来list the current device,如果需要,还可以使用set the device

import torch

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

相关问题 更多 >