Skip to content

Commit

Permalink
Fix cpu inference (open-mmlab#152)
Browse files Browse the repository at this point in the history
* Add missing map_location

* Add docstring

* Update mmseg/apis/inference.py

Co-authored-by: Jerry Jiarui XU <[email protected]>

* Update inference.py

* Update inference.py

Co-authored-by: Jerry Jiarui XU <[email protected]>
  • Loading branch information
daavoo and xvjiarui authored Sep 24, 2020
1 parent 51e4cde commit e385842
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mmseg/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def init_segmentor(config, checkpoint=None, device='cuda:0'):
object.
checkpoint (str, optional): Checkpoint path. If left as None, the model
will not load any weights.
device (str, optional) CPU/CUDA device option. Default 'cuda:0'.
Use 'cpu' for loading model on CPU.
Returns:
nn.Module: The constructed segmentor.
"""
Expand All @@ -28,7 +29,7 @@ def init_segmentor(config, checkpoint=None, device='cuda:0'):
config.model.pretrained = None
model = build_segmentor(config.model, test_cfg=config.test_cfg)
if checkpoint is not None:
checkpoint = load_checkpoint(model, checkpoint)
checkpoint = load_checkpoint(model, checkpoint, map_location='cpu')
model.CLASSES = checkpoint['meta']['CLASSES']
model.PALETTE = checkpoint['meta']['PALETTE']
model.cfg = config # save the config in the model for convenience
Expand Down

0 comments on commit e385842

Please sign in to comment.