JPM
(JPM)
1
Hi,
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.
Thanks!
ptrblck
2
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'])