Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading a saved model #5

Open
cs-mshah opened this issue Jan 13, 2023 · 0 comments
Open

Loading a saved model #5

cs-mshah opened this issue Jan 13, 2023 · 0 comments

Comments

@cs-mshah
Copy link

cs-mshah commented Jan 13, 2023

To resume training I tried to load a saved model from checkpoint, but it ran into the issue where the expected state_dict had module as a prefix to the keys as compared to the saved state_dict.

This is similar to the following issue: pytorch forum, github issue.

I modified the loading code in the following way by adding strict=False for now:

start_epoch = 0
if args.resume:
    assert os.path.isfile(
        args.resume), "Error: no checkpoint directory found!"
    args.out = os.path.dirname(args.resume)
    checkpoint = torch.load(args.resume)
    best_acc = checkpoint['best_acc']
    start_epoch = checkpoint['epoch']
    model.load_state_dict(checkpoint['state_dict'], strict=False)
    optimizer.load_state_dict(checkpoint['optimizer'])
    ema_model.load_state_dict(checkpoint['ema_state_dict'], strict=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant