thanks for the reply. If I comment the squeeze parts I get this other error. Can you please write the code for correct transpose? also, do I eventually need the squeeze part or not?
Entire code can be seen here https://pastebin.com/8p51Zz2A 23
Training complete in 0m 1s
torch.Size([3, 224, 224])
Traceback (most recent call last):
  File "test_loocv.py", line 244, in <module>
    output = model_ft(test_data)
  File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/models/resnet.py", line 139, in forward
  File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 301, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [64, 3, 7, 7], but got input of size [3, 224, 224] instead

The code is:
    model_ft.eval()
    test_data, test_target = image_datasets['train'][idx]
    test_data = test_data.cuda()
    #test_target = test_target.cuda()
    test_target = torch.tensor(test_target)
    test_target = test_target.cuda()
    ##test_data.unsqueeze_(1)
    ##test_target.unsqueeze_(0)
    print(test_data.shape)
    output = model_ft(test_data)