Pytorch使用GPU训练主要有三点注意:
- 判定使用GPU
- 模型转为cuda
- 数据转为cuda
- 输出数据去cuda,转为numpy。
1. 判定使用GPU
下载对应的GPU版本的Pytorch;
**torch.cuda.is_available()**的返回值(True or False)判断GPU是否可用;
**torch.cuda.device_count()**可获得能够使用的GPU数量。
1. 模型转为cuda
##########GPU set##########
torch.manual_seed(0)
torch.cuda.set_device(0)
n_gpu = setgpu(args.gpu