I wanted to access the intermediate outputs of ResNet50, so I created my own class:
class ResNetFeat(nn.Module):
  def __init__(self):
    super(ResNetFeat, self).__init__()
    resnet50_pretrained = models.resnet50(pretrained=True)
    conv_modules = list(resnet50_pretrained.children())[:-2] #all layers expect Adaptive AvgPool2D and FC
    pool_fc_modules = list(resnet50_pretrained.children())[-2:] #layers Adaptive AvgPool2D and FC
    self.model_conv = nn.Sequential(*conv_modules)
    self.pool_fc = nn.Sequential(*pool_fc_modules)
  
  def forward(self, image):
    feat = self.model_conv(image)
    print(feat.shape)
    pred = self.pool_fc(feat)
    return feat, pred

When I test this code:
x_image = torch.randn(1, 3, 224, 224)


featurizer = ResNetFeat()
feat, pred = featurizer(x_image)
print(feat.shape, pred.shape)

I get the following error –
RuntimeError: size mismatch, m1: [2048 x 1], m2: [2048 x 1000] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:940