Cadene / pretrained-models.pytorch

Pretrained ConvNets for pytorch: NASNet, ResNeXt, ResNet, InceptionV4, InceptionResnetV2, Xception, DPN, etc.
BSD 3-Clause "New" or "Revised" License
9.04k stars 1.83k forks source link

torch.save + load don't work #203

Closed pokidyshev closed 2 years ago

pokidyshev commented 4 years ago

Reproduce

import torch
import pretrainedmodels

save_path = "here.pt"
m = pretrainedmodels.resnet18(num_classes=1000, pretrained="imagenet")
torch.save(m, save_path)
torch.load(save_path)

Output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-9b37f0564d0b> in <module>
      5 m = pretrainedmodels.resnet18(num_classes=1000, pretrained="imagenet")
      6 torch.save(m, save_path)
----> 7 torch.load(save_path)

/home/jupyter/dental-notebooks/npokidyshev/bone-loss/bone_loss_env/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    384         f = f.open('rb')
    385     try:
--> 386         return _load(f, map_location, pickle_module, **pickle_load_args)
    387     finally:
    388         if new_fd:

/home/jupyter/dental-notebooks/npokidyshev/bone-loss/bone_loss_env/lib/python3.7/site-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    571     unpickler = pickle_module.Unpickler(f, **pickle_load_args)
    572     unpickler.persistent_load = persistent_load
--> 573     result = unpickler.load()
    574 
    575     deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)

/home/jupyter/dental-notebooks/npokidyshev/bone-loss/bone_loss_env/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
    589                 return modules[name]
    590         raise AttributeError("'{}' object has no attribute '{}'".format(
--> 591             type(self).__name__, name))
    592 
    593     def __setattr__(self, name, value):

AttributeError: 'ResNet' object has no attribute 'features'