Load model incompatible keys

I’m trying to load a model that I saved with fastai (using resnet34 base architecture and save function).

model_path = '../input/resnet34-ship-clf/Resnet34_clf_256x256_1ep.pth'
model = nn.Sequential(models.resnet34())
pretrained_weights = torch.load(model_path)
model.load_state_dict(pretrained_weights, strict=False)

I’ve got the error message : _IncompatibleKeys(missing_keys=['0.conv1.weight' ...

Pre-trained weight names are in the form : 'x.x.x.conv1.weight'
What should I do during loading to get same names ?

Could you try to load the state_dict into the resnet34 directly instead of wrapping it into an nn.Sequential container?

It returns _IncompatibleKeys(missing_keys=['conv1.weight'...
and now pretrained weights are in the form 'x.x.conv1.weight'

I’m not sure how the state_dict was saved, but you could iterate the state_dict, remove the unnecessary two numbers at the beginning, and create a new OrderedDict to load in your model.