Reconstruct saved state_dict model and keep weight

Hi. I fine-tuned a resnet model and ended up with one more layer wrapping the resnet model.

MyResNetModel(
  (model): ResNet(
    (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace)
    (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
    (layer1): Sequential(
      (0): Bottleneck(
        ...
      )
      (1): Bottleneck(
       ...
      )
      ...
   )
)

The ResNet50 default model is:

ResNet(
  (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (relu): ReLU(inplace)
  (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
  (layer1): Sequential(
    (0): Bottleneck(
      ....
    )
    (1): Bottleneck(
      ....
    )
    ....
  )
  (avgpool): AvgPool2d(kernel_size=7, stride=1, padding=0)
  (fc): Linear(in_features=2048, out_features=1000, bias=True)
)
How can I remove the `model` from `MyResNetModel` when loading the state_dict back? Basically, I want to unwrap by getting rid of `(model): ResNet(`
Thank

Could you try to load your state_dict using:

resnet.model.load_state_dict(torch.load(...))