Reputation: 377
i previously saved a model like this:
trainedmodelpath = "model.th"
torch.save({'model': model,
'scaler': scaler,
'encoder': label_encoder,
'config': config_parameters},
trainedmodelpath)
But when i try to load it like this:
PreviousModelPath = "model.th"
TorchLoadedState = torch.load(PreviousModelPath)
TorchLoadedState_Model = TorchLoadedState['model']
model.load_state_dict(TorchLoadedState_Model)
i received this error
*** AttributeError: 'ModelName' object has no attribute 'copy'
Upvotes: 1
Views: 1377
Reputation: 1392
Save model weigths with model.state_dict()
instead:
torch.save({'model': model.state_dict(),
'scaler': scaler,
'encoder': label_encoder,
'config': config_parameters},
trainedmodelpath)
Upvotes: 2