79740619

Date: 2025-08-20 04:38:21
Score: 0.5
Natty:
Report link

Your real problem is that you are trying to reuse a model for only part of its functionality.

The best (only?) way to do that is to load the original model fully. Then delete/ignore the parts that you don't want from that model.
This can be achieved in multiple ways:

model = models.resnet18(pretrained=False)
new_fc = nn.Linear(512, 10)  # must be the same number of input channels as the original layer
new_fc.weights = model.fc.weights[512, :10]  # if you only want to keep the first 10 output features, if the layer has other parameters (bias, buffer), copy them too
model.fc = new_fc
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: ZeSeb