I’ve been trying to make use of pretrained models, their seems to be some issue along the way:
When input is passed to conv layers, the problem persists.
class Model(nn.Module):
def __init__(self, pretrained_model):
super(Model,self).__init__()
self.pretrained_model = pretrained_model
self.base = nn.Sequential(*list(pretrained_model.children())[:-1])
self.linear = nn.Linear(512,340)
def forward(self, x):
x = self.base(x)
x = F.avg_pool2d(x, x.size()[2:])
f = x.view(x.size(0), -1)
y = self.linear(f)
return
ft_model = torchvision.models.resnet18(pretrained=True)
model = Model(ft_model)
k = model(x)
The error occurs at forward module x=self.base(x)
,
Given input size: (512x3x3). Calculated output size: (512x-3x-3).
Also this representation of output size is not consistent .What’s going wrong ? I’m on Pytorch master.