Loading pth.tar files from pytorch to fastai

I would like to load a .pth.tar file from a pytorch repo, into a resnet50.

I am using the resnet50 here: https://github.com/Jia-Research-Lab/GridMask. However when loading the model into a resnet50 learner, I am getting errors about unmatched keys.

I’m doing the following:

action_learn_resnet50 = cnn_learner(dls, resnet50)
checkpoint = torch.load(Path_to_model)
action_learn_resnet50.model.load_state_dict(checkpoint[“state_dict”], strict=True)

I get these errors:

RuntimeError: Error(s) in loading state_dict for Sequential:
Missing key(s) in state_dict: “0.0.weight”, “0.1.weight”, “0.1.bias”, “0.1.running_mean”, “0.1.running_var”, “0.4.0.conv1.weight”, “0.4.0.bn1.weight”, “0.4.0.bn1.bias”, “0.4.0.bn1.running_mean”, “0.4.0.bn1.running_var”, “0.4.0.conv2.weight”, “0.4.0.bn2.weight”, “0.4.0.bn2.bias”, “0.4.0.bn2.running_mean”, “0.4.0.bn2.running_var”, “0.4.0.conv3.weight”, “0.4.0.bn3.weight”, “0.4.0.bn3.bias”, “0.4.0.bn3.running_mean”, “0.4.0.bn3.running_var”, “0.4.0.downsample.0.weight”, “0.4.0.downsample.1.weight”, “0.4.0.downsample.1.bias”, “0.4.0.downsample.1.running_mean”, etc etc etc

What am i doing wrong here?

1 Like