A simple approach of “removing” the last classification layer would be to assign an nn.Identity module to it:
model = models.resnet50()
model.fc = nn.Identity()

x = torch.randn(1, 3, 224, 224)
out = model(x)
print(out.shape)
> torch.Size([1, 2048])

This would basically skip this layer and return the penultimate activation.