Skip to content

Missing keys when loading pretrained weights #278

Open
@BavarianToolbox

Description

@BavarianToolbox

Python 3.8.7
efficientnet-pytorch==0.7.1

There's an issue loading the pre-trained weights (or any saved weights) when using include_top = False

from efficientnet_pytorch import EfficientNet
model = EfficientNet.from_pretrained('efficientnet-b0', include_top = False)

Traceback (most recent call last):
  File "test_file.py", line 2, in <module>
    model = EfficientNet.from_pretrained('efficientnet-b0', include_top = False)
  File "/Users/constantinbaumgartner/Desktop/temp_test/test/lib/python3.8/site-packages/efficientnet_pytorch/model.py", line 378, in from_pretrained
    load_pretrained_weights(model, model_name, weights_path=weights_path,
  File "/Users/constantinbaumgartner/Desktop/temp_test/test/lib/python3.8/site-packages/efficientnet_pytorch/utils.py", line 613, in load_pretrained_weights
    assert not ret.unexpected_keys, 'Missing keys when loading pretrained weights: {}'.format(ret.unexpected_keys)
AssertionError: Missing keys when loading pretrained weights: ['_fc.weight', '_fc.bias']

It seems to be related to the latest release 0.7.1 because the issue doesn't present when using the previous version: efficientnet-pytorch==0.7.0

from efficientnet_pytorch import EfficientNet
model = EfficientNet.from_pretrained('efficientnet-b0', include_top = False)

Loaded pretrained weights for efficientnet-b0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions