Skip to content
Advertisement

How do I create a model from a state dict?

I am trying to load a checkpoint pth file from the faster_rcnn_resnet101 model which is not currently in the PyTorch model zoo. This causes PyTorch to throw a KeyError saying that I the layers in the state dict does not match the model architecture of faster_rcnn_fpn_resnet50 that I’ve loaded from the model zoo.

Note: I tried posting the architecture of the faster_rcnn_fpn_resnet50 model, but I went over the character limit of 30.000

print(state_dict[model].keys()):

backbone.stem.conv1.weight
backbone.stem.conv1.norm.weight
backbone.stem.conv1.norm.bias
backbone.stem.conv1.norm.running_mean
backbone.stem.conv1.norm.running_var
backbone.res2.0.shortcut.weight
backbone.res2.0.shortcut.norm.weight
backbone.res2.0.shortcut.norm.bias
backbone.res2.0.shortcut.norm.running_mean
backbone.res2.0.shortcut.norm.running_var
backbone.res2.0.conv1.weight
backbone.res2.0.conv1.norm.weight
backbone.res2.0.conv1.norm.bias
backbone.res2.0.conv1.norm.running_mean
backbone.res2.0.conv1.norm.running_var
backbone.res2.0.conv2.weight
backbone.res2.0.conv2.norm.weight
backbone.res2.0.conv2.norm.bias
backbone.res2.0.conv2.norm.running_mean
backbone.res2.0.conv2.norm.running_var
backbone.res2.0.conv3.weight
backbone.res2.0.conv3.norm.weight
backbone.res2.0.conv3.norm.bias
backbone.res2.0.conv3.norm.running_mean
backbone.res2.0.conv3.norm.running_var
backbone.res2.1.conv1.weight
backbone.res2.1.conv1.norm.weight
backbone.res2.1.conv1.norm.bias
backbone.res2.1.conv1.norm.running_mean
backbone.res2.1.conv1.norm.running_var
backbone.res2.1.conv2.weight
backbone.res2.1.conv2.norm.weight
backbone.res2.1.conv2.norm.bias
backbone.res2.1.conv2.norm.running_mean
backbone.res2.1.conv2.norm.running_var
backbone.res2.1.conv3.weight
backbone.res2.1.conv3.norm.weight
backbone.res2.1.conv3.norm.bias
backbone.res2.1.conv3.norm.running_mean
backbone.res2.1.conv3.norm.running_var
backbone.res2.2.conv1.weight
backbone.res2.2.conv1.norm.weight
backbone.res2.2.conv1.norm.bias
backbone.res2.2.conv1.norm.running_mean
backbone.res2.2.conv1.norm.running_var
backbone.res2.2.conv2.weight
backbone.res2.2.conv2.norm.weight
backbone.res2.2.conv2.norm.bias
backbone.res2.2.conv2.norm.running_mean
backbone.res2.2.conv2.norm.running_var
backbone.res2.2.conv3.weight
backbone.res2.2.conv3.norm.weight
backbone.res2.2.conv3.norm.bias
backbone.res2.2.conv3.norm.running_mean
backbone.res2.2.conv3.norm.running_var
backbone.res3.0.shortcut.weight
backbone.res3.0.shortcut.norm.weight
backbone.res3.0.shortcut.norm.bias
backbone.res3.0.shortcut.norm.running_mean
backbone.res3.0.shortcut.norm.running_var
backbone.res3.0.conv1.weight
backbone.res3.0.conv1.norm.weight
backbone.res3.0.conv1.norm.bias
backbone.res3.0.conv1.norm.running_mean
backbone.res3.0.conv1.norm.running_var
backbone.res3.0.conv2.weight
backbone.res3.0.conv2.norm.weight
backbone.res3.0.conv2.norm.bias
backbone.res3.0.conv2.norm.running_mean
backbone.res3.0.conv2.norm.running_var
backbone.res3.0.conv3.weight
backbone.res3.0.conv3.norm.weight
backbone.res3.0.conv3.norm.bias
backbone.res3.0.conv3.norm.running_mean
backbone.res3.0.conv3.norm.running_var
backbone.res3.1.conv1.weight
backbone.res3.1.conv1.norm.weight
backbone.res3.1.conv1.norm.bias
backbone.res3.1.conv1.norm.running_mean
backbone.res3.1.conv1.norm.running_var
backbone.res3.1.conv2.weight
backbone.res3.1.conv2.norm.weight
backbone.res3.1.conv2.norm.bias
backbone.res3.1.conv2.norm.running_mean
backbone.res3.1.conv2.norm.running_var
backbone.res3.1.conv3.weight
backbone.res3.1.conv3.norm.weight
backbone.res3.1.conv3.norm.bias
backbone.res3.1.conv3.norm.running_mean
backbone.res3.1.conv3.norm.running_var
backbone.res3.2.conv1.weight
backbone.res3.2.conv1.norm.weight
backbone.res3.2.conv1.norm.bias
backbone.res3.2.conv1.norm.running_mean
backbone.res3.2.conv1.norm.running_var
backbone.res3.2.conv2.weight
backbone.res3.2.conv2.norm.weight
backbone.res3.2.conv2.norm.bias
backbone.res3.2.conv2.norm.running_mean
backbone.res3.2.conv2.norm.running_var
backbone.res3.2.conv3.weight
backbone.res3.2.conv3.norm.weight
backbone.res3.2.conv3.norm.bias
backbone.res3.2.conv3.norm.running_mean
backbone.res3.2.conv3.norm.running_var
backbone.res3.3.conv1.weight
backbone.res3.3.conv1.norm.weight
backbone.res3.3.conv1.norm.bias
backbone.res3.3.conv1.norm.running_mean
backbone.res3.3.conv1.norm.running_var
backbone.res3.3.conv2.weight
backbone.res3.3.conv2.norm.weight
backbone.res3.3.conv2.norm.bias
backbone.res3.3.conv2.norm.running_mean
backbone.res3.3.conv2.norm.running_var
backbone.res3.3.conv3.weight
backbone.res3.3.conv3.norm.weight
backbone.res3.3.conv3.norm.bias
backbone.res3.3.conv3.norm.running_mean
backbone.res3.3.conv3.norm.running_var
backbone.res4.0.shortcut.weight
backbone.res4.0.shortcut.norm.weight
backbone.res4.0.shortcut.norm.bias
backbone.res4.0.shortcut.norm.running_mean
backbone.res4.0.shortcut.norm.running_var
backbone.res4.0.conv1.weight
backbone.res4.0.conv1.norm.weight
backbone.res4.0.conv1.norm.bias
backbone.res4.0.conv1.norm.running_mean
backbone.res4.0.conv1.norm.running_var
backbone.res4.0.conv2.weight
backbone.res4.0.conv2.norm.weight
backbone.res4.0.conv2.norm.bias
backbone.res4.0.conv2.norm.running_mean
backbone.res4.0.conv2.norm.running_var
backbone.res4.0.conv3.weight
backbone.res4.0.conv3.norm.weight
backbone.res4.0.conv3.norm.bias
backbone.res4.0.conv3.norm.running_mean
backbone.res4.0.conv3.norm.running_var
backbone.res4.1.conv1.weight
backbone.res4.1.conv1.norm.weight
backbone.res4.1.conv1.norm.bias
backbone.res4.1.conv1.norm.running_mean
backbone.res4.1.conv1.norm.running_var
backbone.res4.1.conv2.weight
backbone.res4.1.conv2.norm.weight
backbone.res4.1.conv2.norm.bias
backbone.res4.1.conv2.norm.running_mean
backbone.res4.1.conv2.norm.running_var
backbone.res4.1.conv3.weight
backbone.res4.1.conv3.norm.weight
backbone.res4.1.conv3.norm.bias
backbone.res4.1.conv3.norm.running_mean
backbone.res4.1.conv3.norm.running_var
backbone.res4.2.conv1.weight
backbone.res4.2.conv1.norm.weight
backbone.res4.2.conv1.norm.bias
backbone.res4.2.conv1.norm.running_mean
backbone.res4.2.conv1.norm.running_var
backbone.res4.2.conv2.weight
backbone.res4.2.conv2.norm.weight
backbone.res4.2.conv2.norm.bias
backbone.res4.2.conv2.norm.running_mean
backbone.res4.2.conv2.norm.running_var
backbone.res4.2.conv3.weight
backbone.res4.2.conv3.norm.weight
backbone.res4.2.conv3.norm.bias
backbone.res4.2.conv3.norm.running_mean
backbone.res4.2.conv3.norm.running_var
backbone.res4.3.conv1.weight
backbone.res4.3.conv1.norm.weight
backbone.res4.3.conv1.norm.bias
backbone.res4.3.conv1.norm.running_mean
backbone.res4.3.conv1.norm.running_var
backbone.res4.3.conv2.weight
backbone.res4.3.conv2.norm.weight
backbone.res4.3.conv2.norm.bias
backbone.res4.3.conv2.norm.running_mean
backbone.res4.3.conv2.norm.running_var
backbone.res4.3.conv3.weight
backbone.res4.3.conv3.norm.weight
backbone.res4.3.conv3.norm.bias
backbone.res4.3.conv3.norm.running_mean
backbone.res4.3.conv3.norm.running_var
backbone.res4.4.conv1.weight
backbone.res4.4.conv1.norm.weight
backbone.res4.4.conv1.norm.bias
backbone.res4.4.conv1.norm.running_mean
backbone.res4.4.conv1.norm.running_var
backbone.res4.4.conv2.weight
backbone.res4.4.conv2.norm.weight
backbone.res4.4.conv2.norm.bias
backbone.res4.4.conv2.norm.running_mean
backbone.res4.4.conv2.norm.running_var
backbone.res4.4.conv3.weight
backbone.res4.4.conv3.norm.weight
backbone.res4.4.conv3.norm.bias
backbone.res4.4.conv3.norm.running_mean
backbone.res4.4.conv3.norm.running_var
backbone.res4.5.conv1.weight
backbone.res4.5.conv1.norm.weight
backbone.res4.5.conv1.norm.bias
backbone.res4.5.conv1.norm.running_mean
backbone.res4.5.conv1.norm.running_var
backbone.res4.5.conv2.weight
backbone.res4.5.conv2.norm.weight
backbone.res4.5.conv2.norm.bias
backbone.res4.5.conv2.norm.running_mean
backbone.res4.5.conv2.norm.running_var
backbone.res4.5.conv3.weight
backbone.res4.5.conv3.norm.weight
backbone.res4.5.conv3.norm.bias
backbone.res4.5.conv3.norm.running_mean
backbone.res4.5.conv3.norm.running_var
backbone.res4.6.conv1.weight
backbone.res4.6.conv1.norm.weight
backbone.res4.6.conv1.norm.bias
backbone.res4.6.conv1.norm.running_mean
backbone.res4.6.conv1.norm.running_var
backbone.res4.6.conv2.weight
backbone.res4.6.conv2.norm.weight
backbone.res4.6.conv2.norm.bias
backbone.res4.6.conv2.norm.running_mean
backbone.res4.6.conv2.norm.running_var
backbone.res4.6.conv3.weight
backbone.res4.6.conv3.norm.weight
backbone.res4.6.conv3.norm.bias
backbone.res4.6.conv3.norm.running_mean
backbone.res4.6.conv3.norm.running_var
backbone.res4.7.conv1.weight
backbone.res4.7.conv1.norm.weight
backbone.res4.7.conv1.norm.bias
backbone.res4.7.conv1.norm.running_mean
backbone.res4.7.conv1.norm.running_var
backbone.res4.7.conv2.weight
backbone.res4.7.conv2.norm.weight
backbone.res4.7.conv2.norm.bias
backbone.res4.7.conv2.norm.running_mean
backbone.res4.7.conv2.norm.running_var
backbone.res4.7.conv3.weight
backbone.res4.7.conv3.norm.weight
backbone.res4.7.conv3.norm.bias
backbone.res4.7.conv3.norm.running_mean
backbone.res4.7.conv3.norm.running_var
backbone.res4.8.conv1.weight
backbone.res4.8.conv1.norm.weight
backbone.res4.8.conv1.norm.bias
backbone.res4.8.conv1.norm.running_mean
backbone.res4.8.conv1.norm.running_var
backbone.res4.8.conv2.weight
backbone.res4.8.conv2.norm.weight
backbone.res4.8.conv2.norm.bias
backbone.res4.8.conv2.norm.running_mean
backbone.res4.8.conv2.norm.running_var
backbone.res4.8.conv3.weight
backbone.res4.8.conv3.norm.weight
backbone.res4.8.conv3.norm.bias
backbone.res4.8.conv3.norm.running_mean
backbone.res4.8.conv3.norm.running_var
backbone.res4.9.conv1.weight
backbone.res4.9.conv1.norm.weight
backbone.res4.9.conv1.norm.bias
backbone.res4.9.conv1.norm.running_mean
backbone.res4.9.conv1.norm.running_var
backbone.res4.9.conv2.weight
backbone.res4.9.conv2.norm.weight
backbone.res4.9.conv2.norm.bias
backbone.res4.9.conv2.norm.running_mean
backbone.res4.9.conv2.norm.running_var
backbone.res4.9.conv3.weight
backbone.res4.9.conv3.norm.weight
backbone.res4.9.conv3.norm.bias
backbone.res4.9.conv3.norm.running_mean
backbone.res4.9.conv3.norm.running_var
backbone.res4.10.conv1.weight
backbone.res4.10.conv1.norm.weight
backbone.res4.10.conv1.norm.bias
backbone.res4.10.conv1.norm.running_mean
backbone.res4.10.conv1.norm.running_var
backbone.res4.10.conv2.weight
backbone.res4.10.conv2.norm.weight
backbone.res4.10.conv2.norm.bias
backbone.res4.10.conv2.norm.running_mean
backbone.res4.10.conv2.norm.running_var
backbone.res4.10.conv3.weight
backbone.res4.10.conv3.norm.weight
backbone.res4.10.conv3.norm.bias
backbone.res4.10.conv3.norm.running_mean
backbone.res4.10.conv3.norm.running_var
backbone.res4.11.conv1.weight
backbone.res4.11.conv1.norm.weight
backbone.res4.11.conv1.norm.bias
backbone.res4.11.conv1.norm.running_mean
backbone.res4.11.conv1.norm.running_var
backbone.res4.11.conv2.weight
backbone.res4.11.conv2.norm.weight
backbone.res4.11.conv2.norm.bias
backbone.res4.11.conv2.norm.running_mean
backbone.res4.11.conv2.norm.running_var
backbone.res4.11.conv3.weight
backbone.res4.11.conv3.norm.weight
backbone.res4.11.conv3.norm.bias
backbone.res4.11.conv3.norm.running_mean
backbone.res4.11.conv3.norm.running_var
backbone.res4.12.conv1.weight
backbone.res4.12.conv1.norm.weight
backbone.res4.12.conv1.norm.bias
backbone.res4.12.conv1.norm.running_mean
backbone.res4.12.conv1.norm.running_var
backbone.res4.12.conv2.weight
backbone.res4.12.conv2.norm.weight
backbone.res4.12.conv2.norm.bias
backbone.res4.12.conv2.norm.running_mean
backbone.res4.12.conv2.norm.running_var
backbone.res4.12.conv3.weight
backbone.res4.12.conv3.norm.weight
backbone.res4.12.conv3.norm.bias
backbone.res4.12.conv3.norm.running_mean
backbone.res4.12.conv3.norm.running_var
backbone.res4.13.conv1.weight
backbone.res4.13.conv1.norm.weight
backbone.res4.13.conv1.norm.bias
backbone.res4.13.conv1.norm.running_mean
backbone.res4.13.conv1.norm.running_var
backbone.res4.13.conv2.weight
backbone.res4.13.conv2.norm.weight
backbone.res4.13.conv2.norm.bias
backbone.res4.13.conv2.norm.running_mean
backbone.res4.13.conv2.norm.running_var
backbone.res4.13.conv3.weight
backbone.res4.13.conv3.norm.weight
backbone.res4.13.conv3.norm.bias
backbone.res4.13.conv3.norm.running_mean
backbone.res4.13.conv3.norm.running_var
backbone.res4.14.conv1.weight
backbone.res4.14.conv1.norm.weight
backbone.res4.14.conv1.norm.bias
backbone.res4.14.conv1.norm.running_mean
backbone.res4.14.conv1.norm.running_var
backbone.res4.14.conv2.weight
backbone.res4.14.conv2.norm.weight
backbone.res4.14.conv2.norm.bias
backbone.res4.14.conv2.norm.running_mean
backbone.res4.14.conv2.norm.running_var
backbone.res4.14.conv3.weight
backbone.res4.14.conv3.norm.weight
backbone.res4.14.conv3.norm.bias
backbone.res4.14.conv3.norm.running_mean
backbone.res4.14.conv3.norm.running_var
backbone.res4.15.conv1.weight
backbone.res4.15.conv1.norm.weight
backbone.res4.15.conv1.norm.bias
backbone.res4.15.conv1.norm.running_mean
backbone.res4.15.conv1.norm.running_var
backbone.res4.15.conv2.weight
backbone.res4.15.conv2.norm.weight
backbone.res4.15.conv2.norm.bias
backbone.res4.15.conv2.norm.running_mean
backbone.res4.15.conv2.norm.running_var
backbone.res4.15.conv3.weight
backbone.res4.15.conv3.norm.weight
backbone.res4.15.conv3.norm.bias
backbone.res4.15.conv3.norm.running_mean
backbone.res4.15.conv3.norm.running_var
backbone.res4.16.conv1.weight
backbone.res4.16.conv1.norm.weight
backbone.res4.16.conv1.norm.bias
backbone.res4.16.conv1.norm.running_mean
backbone.res4.16.conv1.norm.running_var
backbone.res4.16.conv2.weight
backbone.res4.16.conv2.norm.weight
backbone.res4.16.conv2.norm.bias
backbone.res4.16.conv2.norm.running_mean
backbone.res4.16.conv2.norm.running_var
backbone.res4.16.conv3.weight
backbone.res4.16.conv3.norm.weight
backbone.res4.16.conv3.norm.bias
backbone.res4.16.conv3.norm.running_mean
backbone.res4.16.conv3.norm.running_var
backbone.res4.17.conv1.weight
backbone.res4.17.conv1.norm.weight
backbone.res4.17.conv1.norm.bias
backbone.res4.17.conv1.norm.running_mean
backbone.res4.17.conv1.norm.running_var
backbone.res4.17.conv2.weight
backbone.res4.17.conv2.norm.weight
backbone.res4.17.conv2.norm.bias
backbone.res4.17.conv2.norm.running_mean
backbone.res4.17.conv2.norm.running_var
backbone.res4.17.conv3.weight
backbone.res4.17.conv3.norm.weight
backbone.res4.17.conv3.norm.bias
backbone.res4.17.conv3.norm.running_mean
backbone.res4.17.conv3.norm.running_var
backbone.res4.18.conv1.weight
backbone.res4.18.conv1.norm.weight
backbone.res4.18.conv1.norm.bias
backbone.res4.18.conv1.norm.running_mean
backbone.res4.18.conv1.norm.running_var
backbone.res4.18.conv2.weight
backbone.res4.18.conv2.norm.weight
backbone.res4.18.conv2.norm.bias
backbone.res4.18.conv2.norm.running_mean
backbone.res4.18.conv2.norm.running_var
backbone.res4.18.conv3.weight
backbone.res4.18.conv3.norm.weight
backbone.res4.18.conv3.norm.bias
backbone.res4.18.conv3.norm.running_mean
backbone.res4.18.conv3.norm.running_var
backbone.res4.19.conv1.weight
backbone.res4.19.conv1.norm.weight
backbone.res4.19.conv1.norm.bias
backbone.res4.19.conv1.norm.running_mean
backbone.res4.19.conv1.norm.running_var
backbone.res4.19.conv2.weight
backbone.res4.19.conv2.norm.weight
backbone.res4.19.conv2.norm.bias
backbone.res4.19.conv2.norm.running_mean
backbone.res4.19.conv2.norm.running_var
backbone.res4.19.conv3.weight
backbone.res4.19.conv3.norm.weight
backbone.res4.19.conv3.norm.bias
backbone.res4.19.conv3.norm.running_mean
backbone.res4.19.conv3.norm.running_var
backbone.res4.20.conv1.weight
backbone.res4.20.conv1.norm.weight
backbone.res4.20.conv1.norm.bias
backbone.res4.20.conv1.norm.running_mean
backbone.res4.20.conv1.norm.running_var
backbone.res4.20.conv2.weight
backbone.res4.20.conv2.norm.weight
backbone.res4.20.conv2.norm.bias
backbone.res4.20.conv2.norm.running_mean
backbone.res4.20.conv2.norm.running_var
backbone.res4.20.conv3.weight
backbone.res4.20.conv3.norm.weight
backbone.res4.20.conv3.norm.bias
backbone.res4.20.conv3.norm.running_mean
backbone.res4.20.conv3.norm.running_var
backbone.res4.21.conv1.weight
backbone.res4.21.conv1.norm.weight
backbone.res4.21.conv1.norm.bias
backbone.res4.21.conv1.norm.running_mean
backbone.res4.21.conv1.norm.running_var
backbone.res4.21.conv2.weight
backbone.res4.21.conv2.norm.weight
backbone.res4.21.conv2.norm.bias
backbone.res4.21.conv2.norm.running_mean
backbone.res4.21.conv2.norm.running_var
backbone.res4.21.conv3.weight
backbone.res4.21.conv3.norm.weight
backbone.res4.21.conv3.norm.bias
backbone.res4.21.conv3.norm.running_mean
backbone.res4.21.conv3.norm.running_var
backbone.res4.22.conv1.weight
backbone.res4.22.conv1.norm.weight
backbone.res4.22.conv1.norm.bias
backbone.res4.22.conv1.norm.running_mean
backbone.res4.22.conv1.norm.running_var
backbone.res4.22.conv2.weight
backbone.res4.22.conv2.norm.weight
backbone.res4.22.conv2.norm.bias
backbone.res4.22.conv2.norm.running_mean
backbone.res4.22.conv2.norm.running_var
backbone.res4.22.conv3.weight
backbone.res4.22.conv3.norm.weight
backbone.res4.22.conv3.norm.bias
backbone.res4.22.conv3.norm.running_mean
backbone.res4.22.conv3.norm.running_var
proposal_generator.rpn_head.conv.weight
proposal_generator.rpn_head.conv.bias
proposal_generator.rpn_head.objectness_logits.weight
proposal_generator.rpn_head.objectness_logits.bias
proposal_generator.rpn_head.anchor_deltas.weight
proposal_generator.rpn_head.anchor_deltas.bias
roi_heads.res5.0.shortcut.weight
roi_heads.res5.0.shortcut.norm.weight
roi_heads.res5.0.shortcut.norm.bias
roi_heads.res5.0.shortcut.norm.running_mean
roi_heads.res5.0.shortcut.norm.running_var
roi_heads.res5.0.conv1.weight
roi_heads.res5.0.conv1.norm.weight
roi_heads.res5.0.conv1.norm.bias
roi_heads.res5.0.conv1.norm.running_mean
roi_heads.res5.0.conv1.norm.running_var
roi_heads.res5.0.conv2.weight
roi_heads.res5.0.conv2.norm.weight
roi_heads.res5.0.conv2.norm.bias
roi_heads.res5.0.conv2.norm.running_mean
roi_heads.res5.0.conv2.norm.running_var
roi_heads.res5.0.conv3.weight
roi_heads.res5.0.conv3.norm.weight
roi_heads.res5.0.conv3.norm.bias
roi_heads.res5.0.conv3.norm.running_mean
roi_heads.res5.0.conv3.norm.running_var
roi_heads.res5.1.conv1.weight
roi_heads.res5.1.conv1.norm.weight
roi_heads.res5.1.conv1.norm.bias
roi_heads.res5.1.conv1.norm.running_mean
roi_heads.res5.1.conv1.norm.running_var
roi_heads.res5.1.conv2.weight
roi_heads.res5.1.conv2.norm.weight
roi_heads.res5.1.conv2.norm.bias
roi_heads.res5.1.conv2.norm.running_mean
roi_heads.res5.1.conv2.norm.running_var
roi_heads.res5.1.conv3.weight
roi_heads.res5.1.conv3.norm.weight
roi_heads.res5.1.conv3.norm.bias
roi_heads.res5.1.conv3.norm.running_mean
roi_heads.res5.1.conv3.norm.running_var
roi_heads.res5.2.conv1.weight
roi_heads.res5.2.conv1.norm.weight
roi_heads.res5.2.conv1.norm.bias
roi_heads.res5.2.conv1.norm.running_mean
roi_heads.res5.2.conv1.norm.running_var
roi_heads.res5.2.conv2.weight
roi_heads.res5.2.conv2.norm.weight
roi_heads.res5.2.conv2.norm.bias
roi_heads.res5.2.conv2.norm.running_mean
roi_heads.res5.2.conv2.norm.running_var
roi_heads.res5.2.conv3.weight
roi_heads.res5.2.conv3.norm.weight
roi_heads.res5.2.conv3.norm.bias
roi_heads.res5.2.conv3.norm.running_mean
roi_heads.res5.2.conv3.norm.running_var
roi_heads.box_predictor.cls_score.weight
roi_heads.box_predictor.cls_score.bias
roi_heads.box_predictor.bbox_pred.weight
roi_heads.box_predictor.bbox_pred.bias

Is there a way to dynamically create the model architecture of the faster_rcnn_resnet101 model in torch by iterating over the model dict or is there another way?

I have tried searching for a GitHub repository with a hubconf.py for torch.hub, but to no avail.

Advertisement

Answer

TLDR; the short answer is you can’t.

The state_dict of a nn.Module contains the module’s state, but not its function. It is not possible to instantiate a model with its state dictionary alone.

You can manage to initialize some of the sub-modules based on the state dict keys and the weight shapes, but this is not guaranteed. In any case you won’t be able to know the model’s behaviour because this information is simply not contained in its state dictionary. Therefore you are required to have access to the forward definition of the model in order to know the forward logic, i.e. which functions are applied on the input and intermediate outputs and in which order those submodules are used.


Have a look at this minimal example showing two models with identical state dictionaries. However, their forward is different from one another:

class A(nn.Linear):
    def forward(self, x):
        return super().forward(x)

class B(nn.Linear):
    def forward(self, x):
        return super().forward(x)**2

Here, a and b are initialized and the state dict is copied from one to the other:

>>> a = A(2,1)
>>> b = B(2,1)
>>> a.load_state_dict(b.state_dict())

Both a and b have the exact same state… but actually implement two different functions!

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement