Error message:
trainer.model.save(self.dir, epoch, is_best=is_best)
AttributeError: 'DataParallel' object has no attribute 'save'
Source code analysis:
trainer.model.save(self.dir, epoch, is_best=is_best)
The above code is the code before using single machine multi card parallel. My parallel code is implemented as follows:
os.environ["CUDA_VISIBLE_DEVICES"] = "3,2,1"
model = torch.nn.DataParallel(model,device_ids=[0,1]).cuda()
Cause analysis: attributeerror: ‘dataparallel’ object has no attribute ‘save‘
Under torch multi GPU training, the whole model is stored instead of the model state_Dict(), so we need to use model when calling model Module mode. After using the above modification method, the code is as follows:
trainer.model.module.save(self.dir, epoch, is_best=is_best)
Read More:
- [Solved] Error(s) in loading state_dict for GeneratorResNet
- Pytorch Loading model error: RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict
- [Solved] AttributeError: ‘_IncompatibleKeys‘ object has no attribute ‘parameters‘
- pytorch RuntimeError: Error(s) in loading state_ Dict for dataparall… Import model error solution
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- [Solved] RuntimeError: Error(s) in loading state_dict for BertForTokenClassification
- How to Solve word2vec Module Error: AttributeError & UnicodeDecodeError
- [Solved] AttributeError WriteOnlyWorksheet object has no attribute cell
- [Solved] RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
- pytorch model.load_state_dict Error [How to Solve]
- [Solved] AttributeError: module ‘setuptools._distutils‘ has no attribute ‘version‘
- [Solved] Python 3.6 Error: ‘dict’ object has no attribute ‘has_key’
- AttributeError: module ‘time‘ has no attribute ‘clock‘ [How to Solve]
- [Solved] Python Keras Error: AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘
- AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘ [How to Solve]
- [Solved] Pyg load dataset Error: attributeerror [pytorch geometry]
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]
- [Perfectly Solved] attributeerror: module ‘SciPy. Misc’ has no attribute ‘toimage’ error