Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed load_pretrained_params in PyTorch when ignoring keys #902

Merged
merged 11 commits into from
Apr 28, 2022
Prev Previous commit
Next Next commit
fix: Fixed ResNet
  • Loading branch information
FG Fernandez committed Apr 28, 2022
commit 7de2ddccf78e7b817292fdcfa967e2a747b286c5
11 changes: 4 additions & 7 deletions doctr/models/classification/resnet/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,10 @@ def _resnet(
model = ResNet(num_blocks, output_channels, stage_stride, stage_conv, stage_pooling, cfg=_cfg, **kwargs)
# Load pretrained parameters
if pretrained:
_kwargs = {}
if kwargs['num_classes'] != len(default_cfgs[arch]['classes']):
# The number of classes is not the same as the number of classes in the pretrained model =>
# remove the last layer weights
_kwargs = {"ignore_keys": ignore_keys}
_kwargs = {"ignore_keys": ['13.weight', '13.bias']}
load_pretrained_params(model, default_cfgs[arch]['url'], **_kwargs)
# The number of classes is not the same as the number of classes in the pretrained model =>
# remove the last layer weights
_ignore_keys = ignore_keys if kwargs['num_classes'] == len(default_cfgs[arch]['classes']) else None
load_pretrained_params(model, default_cfgs[arch]['url'], ignore_keys=_ignore_keys)

return model

Expand Down