Issue with output size

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.

Yes, It expects channel first like [bs,C,H,W].

You can use permute in this case.

img = img.permute(0,3,1,2)
# this will change [bs,H,W,C] => [bs,C,H,W]

I did this already as i had mentioned.

what’s the size of input image that you are passing through the network? It seems the input you are passing is having less size than required by pretrained model.