方法一:
分别对网络模型,数据(输入,标注),损失函数调用.cuda()
网络模型:
if torch.cuda.is_available():net=net.cuda()
数据(训练和测试):
if torch.cuda.is_available():imgs=imgs.cuda()targets=targets.cuda()
损失函数:
if torch.cuda.is_available():loss_fn=loss_fn.cuda()
方法二:
.to(device)
Device=torch.device("cpu")
Torch.device("cude:0")
定义训练设备
device=torch.device("cpu")
网络模型
net=net.to(device)
损失函数
loss_fn=loss_fn.to(device)
数据
imgs=imgs.to(device)
targets=targets.to(device)