pytorch_resnet_cifar10
pytorch_resnet_cifar10 copied to clipboard
Inconsistent accuracy when loading weights
I found that the accuracy of the prediction when I loaded the model was inconsistent with the accuracy when I trained it. I think there is a problem with the code part
def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): """ Save the training model """ if(is_best==1): torch.save(state, filename)
is_best needs to make a judgment,Otherwise, the last weight will be saved Further modifications are needed if epoch > 0 and epoch % args.save_every == 0: save_checkpoint({ 'epoch': epoch + 1, 'state_dict': model.state_dict(), 'best_prec1': best_prec1, }, 1, filename=os.path.join(args.save_dir, 'checkpoint.th'))
save_checkpoint({
'state_dict': model.state_dict(),
'best_prec1': best_prec1,
}, is_best, filename=os.path.join(args.save_dir, 'resnet44_best_cifar10.th'))