timm.create_model failed

#1
by feature - opened

model = timm.create_model("hf_hub:FredZhang7/google-safesearch-mini-v2", pretrained=True)

.....
RuntimeError: Error(s) in loading state_dict for InceptionResnetV2:
size mismatch for classif.weight: copying a param with shape torch.Size([2, 1536]) from checkpoint, the shape in current model is torch.Size([3, 1536]).
size mismatch for classif.bias: copying a param with shape torch.Size([2]) from checkpoint, the shape in current model is torch.Size([3]).

BUT

model = timm.create_model('inception_resnet_v2', pretrained=False, num_classes=3)
weights = torch.load('pytorch_model.bin')
model.load_state_dict(weights)

SUCCEEDED

Thank you! I'm looking into it.

Hi!

model = timm.create_model("hf_hub:FredZhang7/google-safesearch-mini-v2", pretrained=True)

shouldn't cause errors anymore. It turned out to be a silly mistake. label_offset in config.json should have been set to 0 (class labels: 0, 1, 2) instead of 1 (class labels: 1, 2).

FredZhang7 changed discussion status to closed

Sign up or log in to comment