I used a resnet50 model(pretrained=True) for training. I saved the best model in training function like:
model.load_state_dict(best_model_wts) return model
then i called my training function:
trained_model = training_func(.....) torch.save(trained_model, 'trained.pth')
Now I want to train again using the weights of my trained model. So what I did is:
pretrained_weights = torch.load('trained.pth'') model = resnet50(pretrained=False) model.load_state_dict(pretrained_weights)
But it throws error:
model.load_state_dict(pretrained_weights) File "/home/user/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 751, in load_state_dict state_dict = state_dict.copy() File "/home/user/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 539, in __getattr__ type(self).__name__, name)) AttributeError: 'ResNet' object has no attribute 'copy'
What I am doing wrong, can you please tell me ? I want to use my trained model’s weights to initialize my new training, same model as before resnet50.