RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
出现这个问题是因为输入模型的tensor加载在cpu中,而模型却加载在cuda上。
解决方法:将输入tensor加载到cuda中,或者把模型加载到cpu
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
img = img.to(device)
output = model(img)
或者:
model = model.cuda()
img = img.cuda()