The error is raised since the activation is flattened in the original resnet before being passed to self.fc as seen here 1. Since you expect a 4D tensor you could try to replace the self.avgpool with the original avgpool layer in combination with your additional modules, and replace self.fc with nn.Identity. Since this approach sounds quite brittle, the proper way would be to write a custom model and override the forward with your desired modules.