a-PyTorch-Tutorial-to-Image-Captioning icon indicating copy to clipboard operation
a-PyTorch-Tutorial-to-Image-Captioning copied to clipboard

pretrained model can't be read

Open kpis-msa opened this issue 4 years ago • 2 comments

I used these source code on google colab by porting. But these codes can't read the pretrained model. The error message is as follows:

`

AttributeError Traceback (most recent call last) in () 208 "dont_smooth": 'smooth'}) 209 # Load model --> 210 checkpoint = torch.load(args.model, map_location=str(device)) 211 decoder = checkpoint['decoder'] 212 decoder = decoder.to(device)

1 frames /usr/local/lib/python3.6/dist-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args) 772 unpickler = pickle_module.Unpickler(f, **pickle_load_args) 773 unpickler.persistent_load = persistent_load --> 774 result = unpickler.load() 775 776 deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)

AttributeError: Can't get attribute 'Encoder' on <module 'models' (namespace)> `

Please provide a correct pretrain model.

kpis-msa avatar Jan 05 '21 04:01 kpis-msa

@sgrvinod @kpis-msa - Getting a similar issue. Is there a solution to this? Migrating to an old pytorch version will work here?

    772     unpickler = pickle_module.Unpickler(f, **pickle_load_args)
    773     unpickler.persistent_load = persistent_load
--> 774     result = unpickler.load()
    775 
    776     deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)

ModuleNotFoundError: No module named 'models'

adib0073 avatar Apr 19 '21 05:04 adib0073

It seems that models.py is required to be in the same folder as the trained model while loading the pytorch model in the old way. This link was helpful for me: https://github.com/pytorch/pytorch/issues/3678

adib0073 avatar Apr 19 '21 17:04 adib0073