Unable To Load Model Weights While Predicting (using Pytorch)
I have trained a Mask RCNN network using PyTorch and am trying to use the obtained weights to predict the location of apples in an image.. I am using the dataset from this paper, a
Solution 1:
There is no 'model'
parameter in the saved checkpoint. If you look in train_rcnn.py:106
:
torch.save(model.state_dict(), os.path.join(args.output_dir, 'model_{}.pth'.format(epoch)))
you see that they save just the model parameters. It should've been something like:
torch.save({
"model": model.state_dict(),
"optimizer": optimizer.state_dict(),
"lr_scheduler": lr_scheduler.state_dict()
}, os.path.join(args.output_dir, 'model_{}.pth'.format(epoch)))
so then after loading you get a dictionary with 'model'
, and the other parameters they appear to be wanting to keep.
This seems to be a bug in their code.
Post a Comment for "Unable To Load Model Weights While Predicting (using Pytorch)"