RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the

RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

This problem occurs because the tensor of the input model is loaded in the CPU, while the model is loaded on CUDA.

Solution: load the input tensor into CUDA or load the model into CPU

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

model = model.to(device)
img = img.to(device)

output = model(img)

Or:

model = model.cuda()
img = img.cuda()

Read More: