报错
device:GPU CPU
?1:RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
sol1:用CUDA训练的模型,测试时要指定设备为CUDA
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")# img = transform(img)后img = img.to(device)# orwith torch.no_grad():output = model(img.to(device))
sol2:调用训练好的模型时,使用CPU
model = torch.load("pretrained_demo_10.pth",map_location=torch.device("cpu"))
