Skip to content

Commit

Permalink
new option to replace optimizer
Browse files Browse the repository at this point in the history
Former-commit-id: 5aabb5a584b873cf86abae21fa21d9d9c10c3f73
  • Loading branch information
Javier Ribera committed Dec 5, 2018
1 parent 3fd4ca4 commit 9f2be09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions object-locator/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def parse_command_args(training_or_testing):
metavar='OPTIM',
choices=['sgd', 'adam'],
help='SGD or Adam')
parser.add_argument('--replace-optimizer',
action='store_true',
default=False,
help='Replace optimizer state when resuming from checkpoint. '
'If True, the optimizer will be replaced as provided in the '
'arguments of this scripts. If not resuming, it has no effect.')
parser.add_argument('--max-mask-pts',
type=int,
default=np.infty,
Expand Down
3 changes: 2 additions & 1 deletion object-locator/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
lowest_mahd = np.infty
print('W: Loaded checkpoint has not been validated. ', end='')
model.load_state_dict(checkpoint['model'])
optimizer.load_state_dict(checkpoint['optimizer'])
if not args.replace_optimizer:
optimizer.load_state_dict(checkpoint['optimizer'])
print(f"\n\__ loaded checkpoint '{args.resume}'"
f"(now on epoch {checkpoint['epoch']})")
else:
Expand Down

0 comments on commit 9f2be09

Please sign in to comment.