Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c186b3

Browse files
authored
Fix lack of proper loading of best_prec1 from the checkpoint (#1000)
- resume() is a nested function and when it loads best_prec1 it creates a local variable that hides the one from the parent function (which refers to the global one). This PR adds `global` to modify the global variable as intended Signed-off-by: Janusz Lisiecki <[email protected]>
1 parent 6b7e77b commit 6c186b3

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

examples/imagenet/main_amp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def resume():
182182
print("=> loading checkpoint '{}'".format(args.resume))
183183
checkpoint = torch.load(args.resume, map_location = lambda storage, loc: storage.cuda(args.gpu))
184184
args.start_epoch = checkpoint['epoch']
185+
global best_prec1
185186
best_prec1 = checkpoint['best_prec1']
186187
model.load_state_dict(checkpoint['state_dict'])
187188
optimizer.load_state_dict(checkpoint['optimizer'])

0 commit comments

Comments
 (0)