pretrained-models.pytorch icon indicating copy to clipboard operation
pretrained-models.pytorch copied to clipboard

Error: 'DenseNet' object has no attribute 'logits'

Open iWangLin opened this issue 7 years ago • 2 comments

I used the pretrainedmodels.densent121 to trian my own dataset, but when I load the model I trianed, I get the error: 'DenseNet' object has no attribute 'logits', I wnant to know why? import pretrainedmodels model_daibao = torch.load('densenet121_daibao_model_1') `AttributeError Traceback (most recent call last) in () 1 import pretrainedmodels ----> 2 model_daibao = torch.load('densenet121_daibao_model_1') 3 model_kouzhao = torch.load('densenet121_kouzhao_model_2') 4 model_yanjing = torch.load('densenet121_yanjing_model_2') 5 model_maozi = torch.load('densenet_maozi_model_1')

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in load(f, map_location, pickle_module) 365 deserialized_objects = {} 366 --> 367 if map_location is None: 368 restore_location = default_restore_location 369 elif isinstance(map_location, dict):

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in _load(f, map_location, pickle_module) 536 if protocol_version != PROTOCOL_VERSION: 537 raise RuntimeError("Invalid protocol version: %s" % protocol_version) --> 538 539 _sys_info = pickle_module.load(f) 540 unpickler = pickle_module.Unpickler(f)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in getattr(self, name) 533 elif params is not None and name in params: 534 if value is not None: --> 535 raise TypeError("cannot assign '{}' as parameter '{}' " 536 "(torch.nn.Parameter or None expected)" 537 .format(torch.typename(value), name))

AttributeError: 'DenseNet' object has no attribute 'logits'`

iWangLin avatar Dec 08 '18 08:12 iWangLin

I have the same problem with Resnet just like you, but I don't know how to solve this problem.

Marco2018 avatar Dec 18 '18 04:12 Marco2018

Hi,

You should save your model using the state dictionary: https://pytorch.org/tutorials/beginner/saving_loading_models.html

Cadene avatar Dec 18 '18 14:12 Cadene