I used the resnet50 model in torchvision.models to train a classification model.Now I want load a new picture to predict.It works when I use the torch.utils.data.DataLoader to feed the picture to my model,but when I load the picture and change it to a torch.Tensor,it dosn’t work.They are all <class ‘torch.Tensor’>,and have same size.The error is size mismatch, m1: [1 x 8192], m2: [2048 x 100].What should I do?Please help me.
CODE:
inputs, classes = next(test_dataloader)
print(type(inputs))
print(inputs.size())
sample = test_datasets.getitem(0)
img = sample[0].float()
img.resize_(1,3,244,244)
print(type(img))
print(img.size())
model_test = ‘resnet50_1’
model_ft = torch.load(model_dir+model_test)
model_ft.eval()
img = img.to(device)
outputs = model_ft(img)
_, preds = torch.max(outputs, 1)