I am getting the error:
RuntimeError: expected type torch.cuda.FloatTensor but got torch.FloatTensor
when running:
scores, classification, transformed_anchors = retinanet(batch)
See code below:
import torch
import model
from torchvision import transforms
from PIL import Image

torch.set_default_tensor_type(torch.cuda.FloatTensor)

def image_loader(loader, image_name):
    image = Image.open(image_name)
    image = loader(image).float()
    image = image.unsqueeze(0)
    return image

def main():

    retinanet = model.resnet50(num_classes=80, pretrained=True, device='cuda:0')
    state_dict_path = 'coco_resnet_50_map_0_335_state_dict.pt'
    retinanet.load_state_dict(torch.load(state_dict_path))
    retinanet = retinanet.cuda()
    retinanet.eval()

    for name, param in retinanet.named_parameters():
        if param.device.type != 'cuda':
            print('param {}, not on GPU'.format(name))

    image_path = 'image.jpg'

    data_transforms = transforms.Compose([
        transforms.Resize(256),
        transforms.CenterCrop(224),
        transforms.ToTensor()
    ])

    batch = image_loader(data_transforms, image_path).cuda()
    print(batch.type())
    print(batch.device)

    with torch.no_grad():
        scores, classification, transformed_anchors = retinanet(batch)

if __name__ == '__main__':
    main()

There is no output when running:
    for name, param in retinanet.named_parameters():
        if param.device.type != 'cuda':
            print('param {}, not on GPU'.format(name))

Implying that every parameter has device type ‘cuda’
And the output from running:
    print(batch.type())
    print(batch.device)

Is:
torch.cuda.FloatTensor
cuda:0

Given that the model and the input tensor are both on the GPU, I’m not sure why I getting this error.
(Note that import model refers to the file https://github.com/AljoSt/pytorch-retinanet/blob/replace_nms/model.py 1 from the repo https://github.com/AljoSt/pytorch-retinanet/tree/replace_nms)