Copy weights from Conv2D with bias=True to Conv2D with bias=False


I have a model that is a sequence of Conv2D with bias=True, I have another model which also is a sequence of Conv2D but with bias=False.

How can I copy the weights from the first model (incorporating the bias) to the second model that just has weights?

Any pointers are greatly appreciated.


Yes, you can skip the additional parameters by using strict=False in load_state_dict as shown here:

conv_bias = nn.Conv2d(3, 3, 3, 1, 1, bias=True)
conv_nobias = nn.Conv2d(3, 3, 3, 1, 1, bias=False)

conv_nobias.load_state_dict(conv_bias.state_dict(), strict=False)
> _IncompatibleKeys(missing_keys=[], unexpected_keys=['bias'])