Hi @ptrblck,
good to hear from you, let me paste the complete code.
model = densenet201()
model.features[0] = nn.Conv2d(1, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
model.features.conv0
Conv2d(1, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
model.classifier = nn.Linear(1920, 264);
model.classifier
Linear(in_features=1920, out_features=264, bias=True)
~/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
1042
1043 if len(error_msgs) > 0:
-> 1044 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
1045 self.__class__.__name__, "\n\t".join(error_msgs)))
1046 return _IncompatibleKeys(missing_keys, unexpected_keys)
RuntimeError: Error(s) in loading state_dict for DenseNet:
Missing key(s) in state_dict: "features.denseblock3.denselayer37.norm1.weight", "features.denseblock3.denselayer37.norm1.bias", "features.denseblock3.denselayer37.norm1.running_mean", "features.denseblock3.denselayer37.norm1.running_var", "features.denseblock3.denselayer37.conv1.weight", "features.denseblock3.denselayer37.norm2.weight", "features.denseblock3.denselayer37.norm2.bias", "features.denseblock.....
and goes for ever to this
size mismatch for features.denseblock4.denselayer24.conv2.weight: copying a param with shape torch.Size([48, 192, 3, 3]) from checkpoint, the shape in current model is torch.Size([32, 128, 3, 3]).
size mismatch for features.norm5.weight: copying a param with shape torch.Size([2208]) from checkpoint, the shape in current model is torch.Size([1920]).
size mismatch for features.norm5.bias: copying a param with shape torch.Size([2208]) from checkpoint, the shape in current model is torch.Size([1920]).
size mismatch for features.norm5.running_mean: copying a param with shape torch.Size([2208]) from checkpoint, the shape in current model is torch.Size([1920]).
size mismatch for features.norm5.running_var: copying a param with shape torch.Size([2208]) from checkpoint, the shape in current model is torch.Size([1920]).
size mismatch for classifier.weight: copying a param with shape torch.Size([264, 2208]) from checkpoint, the shape in current model is torch.Size([264, 1920])
I dont understand because if I have this before I change the model to take one channel
)
(norm5): BatchNorm2d(1920, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(classifier): Linear(in_features=1920, out_features=1000, bias=True)
)
~~
then I just change the last layer with is the classifier
to reduce the output to my classes with this.
model.classifier = nn.Linear(1920,264); model.classifier
Why I am getting this error ?
size mismatch for classifier.weight: copying a param
with shape torch.Size([264, 2208]) from checkpoint, the shape
in current model is torch.Size([264, 1920]).
I dont know what i am doing wrong...... please help.
The funny thing is that when I do it with desenet161,
I dont get any errors.....
If I dont add this line of code I get this error
model.classifier = nn.Linear(1920, dls.c)
size mismatch for classifier.bias: copying a param with shape torch.Size([264]) from checkpoint, the shape in current model is torch.Size([1000]).