Creating the proper Module

username: raph
cooked: <p>Hello there.<br>
I’m still pretty new into the IA world, and I’ve been learning with PyTorch.</p>
<p>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).</p>
<p>When I attempt to load_state_dict on it I get the following error:</p>
<blockquote>
<p>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”.</p>
</blockquote>
<p>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.</p>
<p>I’m quite lost to be honest, any input would be enormously helpful!<br>
Thanks</p>

username: ptrblck
cooked: <p>It might be impossible to recreate the same model architecture, since even if you figure out the modules, you don’t have the <code>forward</code> method, i.e. you don’t have any information about residual connections etc.</p>
<p>Also, you only see the modules containing parameters, while all others are missing.<br>
E.g. <code>conv_block</code> might be defined as:</p>
<pre><code class="lang-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())
</code></pre>
<p>While this will match the <code>state_dict</code> for this submodule, we don’t have any information about all other layers (<code>nn.ReflectionPad</code>, <code>nn.ReLU()</code>, <code>nn.InstanceNorm2d</code>, etc.).</p>