I have been trying to use the pretrained resnet model except for the last fc layer. So I created the self.resnet as follows.
class SimpleNetwork(nn.Module): def __init__(self): super(SimpleNetwork, self).__init__() # Remove the final FC layer of the pretrained Resnet self.pretrained_resnet = models.resnet50(pretrained=True).cuda() self.resnet = nn.Sequential(*list(self.pretrained_resnet.modules())[:-1]).cuda() def forward(self, x): # x : (batch_size, C, H, W) x = torch.randn(50, 3, 224, 224).cuda() x = self.resnet(x)
However, it seems like it is generating the weird error
RuntimeError: input has less dimensions than expected
Note that changing self.resnet to self.pretrained_resnet worked as fine. I don’t understand what can possibly happen by removing one last layer of resnet? Any thoughts?