I want to return the output from the layer 4, avgpool layer and the layer before the fc layer from resnet 18. For that I have written the following code which is showing error as avgpool and fc are being called twice (Once when I define self.avgpool and self.fc, again when I call these in forward method). Thing is, when I create self.avgpool or self.fc, these automatically adds a avgpool and fc layer at the end of resnet even if I don’t call those in the forward method. How can I do this?
Hi @mxahan, thanks for the link. Btw, I replaced the avgpool and fc layers with nn.Identity(). Before the avgpool layer, the dimension of the tensor should be torch.Size([64, 512, 1, 1]) (My input size was (64,3,32,32)). But, even though I replaced both avgpool and fc with nn.Identity(), the result I’m getting has shape torch.Size([64,512]). I think the avgpool layer is still being activated somehow.
I tried manually adding the avgpool and fc layers with self.avgpool and self.fc after replacing the avgpool and fc from resnet with nn.Identity(). But this is not working (The commented out lines)