HI, just making sure if everything is right
in forward function in resnet50 I delete the flatten()
def forward(self, x):
   x = self.conv1(x)
   x = self.bn1(x)
   x = self.relu(x)
   x = self.maxpool(x)
   x = self.layer1(x)
   x = self.layer2(x)
   x = self.layer3(x)
   x = self.layer4(x)
   x = self.avgpool(x)
   #x = torch.flatten(x)
   x = self.fc(x)
       return x

And after constructing the model ,I do what you said
model_resnet = resnet50()
resnet50_weights = torch.load("resnet50-19c8e357.pth")
model_resnet.load_state_dict(resnet50_weights)
model_resnet.fc = nn.Identity()
model_resnet.avgpool = nn.Identity()

And without flatten, I think the output shape would right now be same as last residual block output shape,if you find anything wrong above,please do correct me .Thanks!