Creating the proper Module

Hello there.
I’m still pretty new into the IA world, and I’ve been learning with PyTorch.

My goal is to replicate the structure of a Module to accommodate an existing trained model (which I don’t have the structure of the module).

When I attempt to load_state_dict on it I get the following error:

Unexpected key(s) in state_dict: “model.1.weight”, “model.1.bias”, “model.4.weight”, “model.4.bias”, “model.7.weight”, “model.7.bias”, “model.10.weight”, “model.10.bias”, “model.13.weight”, “model.13.bias”, “model.16.conv_block.1.weight”, “model.16.conv_block.1.bias”, “model.16.conv_block.5.weight”, “model.16.conv_block.5.bias”, “model.17.conv_block.1.weight”, “model.17.conv_block.1.bias”, “model.17.conv_block.5.weight”, “model.17.conv_block.5.bias”, “model.18.conv_block.1.weight”, “model.18.conv_block.1.bias”, “model.18.conv_block.5.weight”, “model.18.conv_block.5.bias”, “model.19.conv_block.1.weight”, “model.19.conv_block.1.bias”, “model.19.conv_block.5.weight”, “model.19.conv_block.5.bias”, “model.20.conv_block.1.weight”, “model.20.conv_block.1.bias”, “model.20.conv_block.5.weight”, “model.20.conv_block.5.bias”, “model.21.conv_block.1.weight”, “model.21.conv_block.1.bias”, “model.21.conv_block.5.weight”, “model.21.conv_block.5.bias”, “model.22.conv_block.1.weight”, “model.22.conv_block.1.bias”, “model.22.conv_block.5.weight”, “model.22.conv_block.5.bias”, “model.23.conv_block.1.weight”, “model.23.conv_block.1.bias”, “model.23.conv_block.5.weight”, “model.23.conv_block.5.bias”, “model.24.conv_block.1.weight”, “model.24.conv_block.1.bias”, “model.24.conv_block.5.weight”, “model.24.conv_block.5.bias”, “model.25.weight”, “model.25.bias”, “model.28.weight”, “model.28.bias”, “model.31.weight”, “model.31.bias”, “model.34.weight”, “model.34.bias”, “model.38.weight”, “model.38.bias”.

I cannot seem to find a way to create a model with such characteristics, I do believe it has an array of torch.nn.Module, that those might have an array of toch.nn.Conv2d. Been looking into it for the past few hours and I cannot figure it out.

I’m quite lost to be honest, any input would be enormously helpful!
Thanks

It might be impossible to recreate the same model architecture, since even if you figure out the modules, you don’t have the forward method, i.e. you don’t have any information about residual connections etc.

Also, you only see the modules containing parameters, while all others are missing.
E.g. conv_block might be defined as:

features = 1
conv_block = [
            nn.ReflectionPad2d(1),
            nn.Conv2d(features, features, 3),
            nn.InstanceNorm2d(features),
            nn.ReLU(inplace=True),
            nn.ReflectionPad2d(1),
            nn.Conv2d(features, features, 3),
            nn.InstanceNorm2d(features),
        ]

conv_block = nn.Sequential(*conv_block)
print(conv_block.state_dict().keys())

While this will match the state_dict for this submodule, we don’t have any information about all other layers (nn.ReflectionPad, nn.ReLU(), nn.InstanceNorm2d, etc.).