[Fix] Fix a bug when load checkpoints in mulit-GPUs environment. (#527)

* Fix a bug when load checkpoints in mulit-GPUs environment.

* Map the weights to CPU
pull/531/head
Ma Zerun 2021-11-10 17:54:43 +08:00 committed by GitHub
parent 87c67a6a79
commit e0d32df076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -34,8 +34,9 @@ def init_model(config, checkpoint=None, device='cuda:0', options=None):
config.model.pretrained = None
model = build_classifier(config.model)
if checkpoint is not None:
map_loc = 'cpu' if device == 'cpu' else None
checkpoint = load_checkpoint(model, checkpoint, map_location=map_loc)
# Mapping the weights to GPU may cause unexpected video memory leak
# which refers to https://github.com/open-mmlab/mmdetection/pull/6405
checkpoint = load_checkpoint(model, checkpoint, map_location='cpu')
if 'CLASSES' in checkpoint.get('meta', {}):
model.CLASSES = checkpoint['meta']['CLASSES']
else: