When I am trying to load a model :
Load the trained model from file
trained_model = Net() #Net is myModelClass
m = torch.load(’./modell.pth’, map_location=lambda storage, loc: storage)
trained_model.load_state_dict(m)
trained_model.load_state_dict(m)
File “/home/surya/myenv/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 751, in load_state_dict
state_dict = state_dict.copy()
File “/home/surya/myenv/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 539, in getattr
type(self).name, name))
AttributeError: ‘Net’ object has no attribute ‘copy’
Next I have used copy.copy(state_dict). Then I got a new error.
trained_model.load_state_dict(m)
File “/home/surya/myenv/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 763, in load_state_dict
load(self)
File “/home/surya/myenv/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 758, in load
state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs)
File “/home/surya/myenv/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 720, in _load_from_state_dict
for key in state_dict.keys():
File “/home/surya/myenv/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 539, in getattr
type(self).name, name))
AttributeError: ‘Net’ object has no attribute ‘keys’