From c0e7512969877e0231340c82908720cd1fbef8f7 Mon Sep 17 00:00:00 2001 From: LXXXXR <73265258+LXXXXR@users.noreply.github.com> Date: Wed, 25 Nov 2020 16:14:01 +0800 Subject: [PATCH] support options to override configs in inference.py (#96) --- mmcls/apis/inference.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mmcls/apis/inference.py b/mmcls/apis/inference.py index 9511875ca..61d161e18 100644 --- a/mmcls/apis/inference.py +++ b/mmcls/apis/inference.py @@ -11,7 +11,7 @@ from mmcls.datasets.pipelines import Compose from mmcls.models import build_classifier -def init_model(config, checkpoint=None, device='cuda:0'): +def init_model(config, checkpoint=None, device='cuda:0', options=None): """Initialize a classifier from config file. Args: @@ -19,6 +19,7 @@ def init_model(config, checkpoint=None, device='cuda:0'): object. checkpoint (str, optional): Checkpoint path. If left as None, the model will not load any weights. + options (dict): Options to override some settings in the used config. Returns: nn.Module: The constructed classifier. @@ -28,6 +29,8 @@ def init_model(config, checkpoint=None, device='cuda:0'): elif not isinstance(config, mmcv.Config): raise TypeError('config must be a filename or Config object, ' f'but got {type(config)}') + if options is not None: + config.merge_from_dict(options) config.model.pretrained = None model = build_classifier(config.model) if checkpoint is not None: