# Creating the proper Module

**URL:** <https://discuss.pytorch.org/t/creating-the-proper-module/49298>\
**Category:** vision\
**Created:** [June 30, 2019, 12:25am UTC](https://discuss.pytorch.org/t/creating-the-proper-module/49298 "2019-06-30T00:25:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![raph](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@raph](https://discuss.pytorch.org/u/raph)\
**Post date:** [June 30, 2019, 12:25am UTC](https://discuss.pytorch.org/t/creating-the-proper-module/49298/1 "2019-06-30T00:25:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [June 30, 2019, 12:20pm UTC](https://discuss.pytorch.org/t/creating-the-proper-module/49298/2 "2019-06-30T12:20:20Z")

</div>

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:

```python
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.).
