I use checkpoint to save the information of trained model, but when I load model, the grad of parameter is none. How to maintain grad in checkpoint ?
print("Best accuracy: ", best_prec1)
save_checkpoint({
‘epoch’: epoch + 1,
‘state_dict’: model.state_dict(keep_vars=True),
‘best_prec1’: best_prec1,
‘optimizer’: optimizer.state_dict(),
}, is_best, filepath=args.save)
if args.model:
if os.path.isfile(args.model):
print("=> loading checkpoint ‘{}’".format(args.model))
checkpoint = torch.load(args.model)
args.start_epoch = checkpoint[‘epoch’]
best_prec1 = checkpoint[‘best_prec1’]
model.load_state_dict(checkpoint[‘state_dict’])
print("=> loaded checkpoint ‘{}’ (epoch {}) Prec1: {:f}"
.format(args.model, checkpoint[‘epoch’], best_prec1))
else:
print("=> no checkpoint found at ‘{}’".format(args.resume))