I am new to Pytorch, and I obtained a pertained model only (without model definition in python), and I can load it using command:
which was successful, and I can pass input data to mnet. Now I hope to use the feature from the 3rd last layer as output, so I am doing this:
mnet = torch.hub.load(...) self.list_block=list(mnet.children())[:-2] self.encoder= nn.Sequential(*self.list_block)
However, when I pass input data to encoder, I got the following error:
TypeError: forward() takes 1 positional argument but 2 were given
Could someone provide some guidance on how to fix the above issue?
The input is just a tensor with shape [16, 3, 256, 256], and it worked well for all earlier experiments with mainstream structures. For the new experiments, I just replaced the CNN with a pretrained mnet (also worked well). But the problem is with the “extracting intermediate feature” operation. I searched online, and “take 1 positional argument but 2 were given” error is usually because forward() of self.encoder expects additioin input “self” (which I don’t understand…). I don’t have the model definition, but it was automatically loaded by torch.hub.load(…) command.