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

Load weights on segmentation/train.py when using --resume and --test-only flags #3285

Merged
merged 2 commits into from
Jan 25, 2021

Conversation

datumbox
Copy link
Contributor

A good way to verify the accuracy of a specific epoch checkpoint on the evaluation dataset is to execute:

python -m torch.distributed.launch --nproc_per_node=2 --use_env train.py --dataset coco --model model_name_here\ 
  --test-only --resume /path/to/checkpoint.pth

This is supported on both the classification and detection reference scripts but not on segmentation. More specifically on segmentation, the specified weights are not loaded and thus we report the accuracy of randomly initialized weights. This PR fixes this.

Copy link
Contributor Author

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few notes on the implementation:

optimizer.load_state_dict(checkpoint['optimizer'])
lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
args.start_epoch = checkpoint['epoch'] + 1
model_without_ddp.load_state_dict(checkpoint['model'], strict=not args.test_only)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict=False required to avoid having to configure auxiliary classifiers

args.start_epoch = checkpoint['epoch'] + 1
model_without_ddp.load_state_dict(checkpoint['model'], strict=not args.test_only)
if not args.test_only:
optimizer.load_state_dict(checkpoint['optimizer'])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid loading the weights of other objects if in test-only mode. Similar to the above, this is done to avoid having to handle auxiliary classifiers.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for improving this Vasilis!

@fmassa fmassa merged commit 1ebda73 into pytorch:master Jan 25, 2021
@datumbox datumbox deleted the bugfix/segmentation_testonly branch January 25, 2021 09:46
facebook-github-bot pushed a commit that referenced this pull request Feb 1, 2021
Summary: Co-authored-by: Francisco Massa <fvsmassa@gmail.com>

Reviewed By: datumbox

Differential Revision: D26156373

fbshipit-source-id: 83f22c90477ca2da8db176d2455a70ca302d17d1
@datumbox datumbox added the bug label Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants