facebookresearch / ClassyVision

An end-to-end PyTorch framework for image and video classification
https://classyvision.ai
MIT License
1.59k stars 278 forks source link

Can you provide the pre-trained Efficientnet.torch or the trunk? #691

Closed shinianzhihou closed 3 years ago

shinianzhihou commented 3 years ago

I'm trying to load the pre-trained model (efficientnet) for another repo but the keys doesn't match. Can you pls provide the pre-trained Efficientnet.torch or the trunk.pt ? or provide any ideas for this problem:

RuntimeError: Error(s) in loading state_dict for EfficientNet:
    Unexpected key(s) in state_dict: "_conv_stem.weight", "_bn0.weight", "_bn0.bias", "_bn0.running_mean", "_bn0.running_var", "_bn0.num_batches_tracked", "_blocks.0._depthwise_conv.weight", "_blocks.0._bn1.weight", "_blocks.0._bn1.bias", "_blocks.0._bn1.running_mean", "_blocks.0._bn1.running_var",
.........
mannatsingh commented 3 years ago

Hi @shinianzhihou we don't have any plans currently of supporting pre-trained models. But if you have weights from any repository, you can easily write a script which maps the keys to the right format - this code would have to depend on the source implementation though. As a small example,

class TestModel1(nn.Module):
    def __init__(self):
        ...
        self.conv1 = nn.Conv2d(1, 2, 3)
class TestModel2(nn.Module):
    def __init__(self):
        ...
        self.c1 = nn.Conv2d(1, 2, 3)

To use the state dictionary from TestModel1 in TestModel2, the "conv1" key would have to be renamed to "c1". The easiest way to do this is to print the keys for both model states and look at the implementations to see which key maps to which in the two dicts.

Another option is to re-use the source implementation in Classy Vision - you can bring your own model in Classy Vision easily :) see https://classyvision.ai/tutorials/classy_model for examples

shinianzhihou commented 3 years ago

Thanks for your reply, I have solved this problem !