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

I moved my model to gpu

net.to(device)

but when i try to test the model , as per the
Pytorch tutorial

dataiter = iter(testloader)
images, labels = dataiter.next()

imshow(torchvision.utils.make_grid(images))
print('GroundTruth: ', ' '.join('%5s' % classes[labels[j]] for j in range(4)))

outputs = net(images)  #This line throws the error

what is the issue ???

1 Like

You need to pass images to device also.

pass images to device by using below code

dataiter = iter(testloader)
images, labels = dataiter.next()
images,labels = images.to(device),labels.to(device)
2 Likes

Thanks man , it worked

I have a problem. i mounted my data on google drive and when i want to train my model it has an issue same as below:

Make sure to push the input data to the device using:

input = input.cuda()
# or
input = input.to('cuda')

thankyou so much. it helped.

‫‪ptrblck via PyTorch Forums‬‏ <‪noreply@discuss.pytorch.org‬‏> در تاریخ دوشنبه ۶ آوریل ۲۰۲۰ ساعت ۸:۱۰ نوشت:‬