Error: 'DenseNet' object has no attribute 'logits'
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)
/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'`
I have the same problem with Resnet just like you, but I don't know how to solve this problem.
Hi,
You should save your model using the state dictionary: https://pytorch.org/tutorials/beginner/saving_loading_models.html