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
fix: Fixed load conditions
  • Loading branch information
FG Fernandez committed Apr 28, 2022
commit 5165d30e358abb7c4403065ef547fc3ac1761a98
2 changes: 1 addition & 1 deletion doctr/models/classification/magc_resnet/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _magc_resnet(
if pretrained:
# 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
_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
2 changes: 1 addition & 1 deletion doctr/models/classification/mobilenet/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _mobilenet_v3(
if pretrained:
# 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
_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)

model.cfg = _cfg
Expand Down
4 changes: 2 additions & 2 deletions doctr/models/classification/resnet/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _resnet(
if pretrained:
# 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
_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 Expand Up @@ -205,7 +205,7 @@ def _tv_resnet(
if pretrained:
# 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
_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)

model.cfg = _cfg
Expand Down
2 changes: 1 addition & 1 deletion doctr/models/classification/vgg/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _vgg(
if pretrained:
# 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
_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)

model.cfg = _cfg
Expand Down
2 changes: 1 addition & 1 deletion doctr/models/recognition/crnn/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _crnn(
if pretrained:
# 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 _cfg['vocab'] == default_cfgs[arch]['vocab'] else None
_ignore_keys = ignore_keys if _cfg['vocab'] != default_cfgs[arch]['vocab'] else None
load_pretrained_params(model, _cfg['url'], ignore_keys=_ignore_keys)

return model
Expand Down