prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Make MMDetection config object accessible to users
  ## 🚀 Feature
  Make MMDetection config object accessible to users. The goal is to be able to update model attributes: e.g. changing weighted loss parameters, changing anchor boxes ratios, etc.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `icevision/models/mmdet/common/utils.py`
  Content:
  ```
  1 __all__ = [
  2     "convert_background_from_zero_to_last",
  3     "convert_background_from_last_to_zero",
  4     "mmdet_tensor_to_image",
  5     "build_model",
  6 ]
  7 
  8 from icevision.imports import *
  9 from icevision.utils import *
  10 from mmcv import Config
  11 from mmdet.models import build_detector
  12 from mmcv.runner import load_checkpoint
  13 from icevision.models.mmdet.utils import *
  14 
  15 
  16 def convert_background_from_zero_to_last(label_ids, class_map):
  17     label_ids = label_ids - 1
  18     label_ids[label_ids == -1] = class_map.num_classes - 1
  19     return label_ids
  20 
  21 
  22 def convert_background_from_last_to_zero(label_ids, class_map):
  23     label_ids = label_ids + 1
  24     label_ids[label_ids == len(class_map)] = 0
  25     return label_ids
  26 
  27 
  28 def mmdet_tensor_to_image(tensor_image):
  29     return tensor_to_image(tensor_image)[:, :, ::-1].copy()
  30 
  31 
  32 def build_model(
  33     model_type: str,
  34     backbone: MMDetBackboneConfig,
  35     num_classes: int,
  36     pretrained: bool = True,
  37     checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
  38     force_download=False,
  39 ) -> nn.Module:
  40 
  41     cfg, weights_path = create_model_config(
  42         backbone=backbone,
  43         pretrained=pretrained,
  44         checkpoints_path=checkpoints_path,
  45         force_download=force_download,
  46     )
  47 
  48     if model_type == "one_stage_detector_bbox":
  49         cfg.model.bbox_head.num_classes = num_classes - 1
  50 
  51     if model_type == "two_stage_detector_bbox":
  52         # Sparse-RCNN has a list of bbox_head whereas Faster-RCNN has only one
  53         if isinstance(cfg.model.roi_head.bbox_head, list):
  54             for bbox_head in cfg.model.roi_head.bbox_head:
  55                 bbox_head["num_classes"] = num_classes - 1
  56         else:
  57             cfg.model.roi_head.bbox_head.num_classes = num_classes - 1
  58 
  59     if model_type == "two_stage_detector_mask":
  60         cfg.model.roi_head.bbox_head.num_classes = num_classes - 1
  61         cfg.model.roi_head.mask_head.num_classes = num_classes - 1
  62 
  63     if (pretrained == False) or (weights_path is not None):
  64         cfg.model.pretrained = None
  65 
  66     _model = build_detector(cfg.model, cfg.get("train_cfg"), cfg.get("test_cfg"))
  67     _model.init_weights()
  68 
  69     if pretrained and (weights_path is not None):
  70         load_checkpoint(_model, str(weights_path))
  71 
  72     _model.param_groups = MethodType(param_groups, _model)
  73 
  74     return _model
  75
  ```
  
  Path: `icevision/models/mmdet/utils.py`
  Content:
  ```
  1 __all__ = [
  2     "MMDetBackboneConfig",
  3     "mmdet_configs_path",
  4     "param_groups",
  5     "MMDetBackboneConfig",
  6     "create_model_config",
  7 ]
  8 
  9 from icevision.imports import *
  10 from icevision.utils import *
  11 from icevision.backbones import BackboneConfig
  12 from icevision.models.mmdet.download_configs import download_mmdet_configs
  13 from mmdet.models.detectors import *
  14 from mmcv import Config
  15 from mmdet.models.backbones.ssd_vgg import SSDVGG
  16 
  17 
  18 mmdet_configs_path = download_mmdet_configs()
  19 
  20 
  21 class MMDetBackboneConfig(BackboneConfig):
  22     def __init__(self, model_name, config_path, weights_url):
  23         self.model_name = model_name
  24         self.config_path = config_path
  25         self.weights_url = weights_url
  26         self.pretrained: bool
  27 
  28     def __call__(self, pretrained: bool = True) -> "MMDetBackboneConfig":
  29         self.pretrained = pretrained
  30         return self
  31 
  32 
  33 def param_groups(model):
  34     body = model.backbone
  35 
  36     layers = []
  37     if isinstance(body, SSDVGG):
  38         layers += [body.features]
  39         layers += [body.extra, body.l2_norm]
  40     else:
  41         layers += [nn.Sequential(body.conv1, body.bn1)]
  42         layers += [getattr(body, l) for l in body.res_layers]
  43         layers += [model.neck]
  44 
  45     if isinstance(model, SingleStageDetector):
  46         layers += [model.bbox_head]
  47     elif isinstance(model, TwoStageDetector):
  48         layers += [nn.Sequential(model.rpn_head, model.roi_head)]
  49     else:
  50         raise RuntimeError(
  51             "{model} must inherit either from SingleStageDetector or TwoStageDetector class"
  52         )
  53 
  54     _param_groups = [list(layer.parameters()) for layer in layers]
  55     check_all_model_params_in_groups2(model, _param_groups)
  56     return _param_groups
  57 
  58 
  59 def create_model_config(
  60     backbone: MMDetBackboneConfig,
  61     pretrained: bool = True,
  62     checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
  63     force_download=False,
  64 ):
  65 
  66     model_name = backbone.model_name
  67     config_path = backbone.config_path
  68     weights_url = backbone.weights_url
  69 
  70     # download weights
  71     weights_path = None
  72     if pretrained and weights_url:
  73         save_dir = Path(checkpoints_path) / model_name
  74         save_dir.mkdir(exist_ok=True, parents=True)
  75 
  76         fname = Path(weights_url).name
  77         weights_path = save_dir / fname
  78 
  79         if not weights_path.exists() or force_download:
  80             download_url(url=weights_url, save_path=str(weights_path))
  81 
  82     cfg = Config.fromfile(config_path)
  83 
  84     return cfg, weights_path
  85
  ```
  
  Path: `icevision/models/mmdet/common/bbox/single_stage/model.py`
  Content:
  ```
  1 __all__ = ["model"]
  2 
  3 from icevision.imports import *
  4 from mmcv import Config
  5 from mmdet.models import build_detector
  6 from mmcv.runner import load_checkpoint
  7 from icevision.models.mmdet.utils import *
  8 from icevision.utils.download_utils import *
  9 from icevision.models.mmdet.common.utils import *
  10 
  11 
  12 def model(
  13     backbone: MMDetBackboneConfig,
  14     num_classes: int,
  15     checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
  16     force_download=False,
  17 ) -> nn.Module:
  18 
  19     return build_model(
  20         model_type="one_stage_detector_bbox",
  21         backbone=backbone,
  22         num_classes=num_classes,
  23         pretrained=backbone.pretrained,
  24         checkpoints_path=checkpoints_path,
  25         force_download=force_download,
  26     )
  27
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/icevision/models/mmdet/common/bbox/single_stage/model.py b/icevision/models/mmdet/common/bbox/single_stage/model.py
  --- a/icevision/models/mmdet/common/bbox/single_stage/model.py
  +++ b/icevision/models/mmdet/common/bbox/single_stage/model.py
  @@ -14,6 +14,7 @@
       num_classes: int,
       checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
       force_download=False,
  +    cfg_options=None,
   ) -> nn.Module:
   
       return build_model(
  @@ -23,4 +24,5 @@
           pretrained=backbone.pretrained,
           checkpoints_path=checkpoints_path,
           force_download=force_download,
  +        cfg_options=cfg_options,
       )
  diff --git a/icevision/models/mmdet/common/utils.py b/icevision/models/mmdet/common/utils.py
  --- a/icevision/models/mmdet/common/utils.py
  +++ b/icevision/models/mmdet/common/utils.py
  @@ -36,6 +36,7 @@
       pretrained: bool = True,
       checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
       force_download=False,
  +    cfg_options=None,
   ) -> nn.Module:
   
       cfg, weights_path = create_model_config(
  @@ -43,6 +44,7 @@
           pretrained=pretrained,
           checkpoints_path=checkpoints_path,
           force_download=force_download,
  +        cfg_options=cfg_options,
       )
   
       if model_type == "one_stage_detector_bbox":
  @@ -70,5 +72,7 @@
           load_checkpoint(_model, str(weights_path))
   
       _model.param_groups = MethodType(param_groups, _model)
  +    _model.cfg = cfg  # save the config in the model for convenience
  +    _model.weights_path = weights_path  # save the model.weights_path in case we want to rebuild the model after updating its attributes
   
       return _model
  diff --git a/icevision/models/mmdet/utils.py b/icevision/models/mmdet/utils.py
  --- a/icevision/models/mmdet/utils.py
  +++ b/icevision/models/mmdet/utils.py
  @@ -61,6 +61,7 @@
       pretrained: bool = True,
       checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
       force_download=False,
  +    cfg_options=None,
   ):
   
       model_name = backbone.model_name
  @@ -81,4 +82,7 @@
   
       cfg = Config.fromfile(config_path)
   
  +    if cfg_options is not None:
  +        cfg.merge_from_dict(cfg_options)
  +
       return cfg, weights_path
  
verification_info: {"golden_diff": "diff --git a/icevision/models/mmdet/common/bbox/single_stage/model.py b/icevision/models/mmdet/common/bbox/single_stage/model.py\n--- a/icevision/models/mmdet/common/bbox/single_stage/model.py\n+++ b/icevision/models/mmdet/common/bbox/single_stage/model.py\n@@ -14,6 +14,7 @@\n     num_classes: int,\n     checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n     force_download=False,\n+    cfg_options=None,\n ) -> nn.Module:\n \n     return build_model(\n@@ -23,4 +24,5 @@\n         pretrained=backbone.pretrained,\n         checkpoints_path=checkpoints_path,\n         force_download=force_download,\n+        cfg_options=cfg_options,\n     )\ndiff --git a/icevision/models/mmdet/common/utils.py b/icevision/models/mmdet/common/utils.py\n--- a/icevision/models/mmdet/common/utils.py\n+++ b/icevision/models/mmdet/common/utils.py\n@@ -36,6 +36,7 @@\n     pretrained: bool = True,\n     checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n     force_download=False,\n+    cfg_options=None,\n ) -> nn.Module:\n \n     cfg, weights_path = create_model_config(\n@@ -43,6 +44,7 @@\n         pretrained=pretrained,\n         checkpoints_path=checkpoints_path,\n         force_download=force_download,\n+        cfg_options=cfg_options,\n     )\n \n     if model_type == \"one_stage_detector_bbox\":\n@@ -70,5 +72,7 @@\n         load_checkpoint(_model, str(weights_path))\n \n     _model.param_groups = MethodType(param_groups, _model)\n+    _model.cfg = cfg  # save the config in the model for convenience\n+    _model.weights_path = weights_path  # save the model.weights_path in case we want to rebuild the model after updating its attributes\n \n     return _model\ndiff --git a/icevision/models/mmdet/utils.py b/icevision/models/mmdet/utils.py\n--- a/icevision/models/mmdet/utils.py\n+++ b/icevision/models/mmdet/utils.py\n@@ -61,6 +61,7 @@\n     pretrained: bool = True,\n     checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n     force_download=False,\n+    cfg_options=None,\n ):\n \n     model_name = backbone.model_name\n@@ -81,4 +82,7 @@\n \n     cfg = Config.fromfile(config_path)\n \n+    if cfg_options is not None:\n+        cfg.merge_from_dict(cfg_options)\n+\n     return cfg, weights_path\n", "issue": "Make MMDetection config object accessible to users\n## \ud83d\ude80 Feature\r\nMake MMDetection config object accessible to users. The goal is to be able to update model attributes: e.g. changing weighted loss parameters, changing anchor boxes ratios, etc.\r\n\n", "before_files": [{"content": "__all__ = [\n    \"convert_background_from_zero_to_last\",\n    \"convert_background_from_last_to_zero\",\n    \"mmdet_tensor_to_image\",\n    \"build_model\",\n]\n\nfrom icevision.imports import *\nfrom icevision.utils import *\nfrom mmcv import Config\nfrom mmdet.models import build_detector\nfrom mmcv.runner import load_checkpoint\nfrom icevision.models.mmdet.utils import *\n\n\ndef convert_background_from_zero_to_last(label_ids, class_map):\n    label_ids = label_ids - 1\n    label_ids[label_ids == -1] = class_map.num_classes - 1\n    return label_ids\n\n\ndef convert_background_from_last_to_zero(label_ids, class_map):\n    label_ids = label_ids + 1\n    label_ids[label_ids == len(class_map)] = 0\n    return label_ids\n\n\ndef mmdet_tensor_to_image(tensor_image):\n    return tensor_to_image(tensor_image)[:, :, ::-1].copy()\n\n\ndef build_model(\n    model_type: str,\n    backbone: MMDetBackboneConfig,\n    num_classes: int,\n    pretrained: bool = True,\n    checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n    force_download=False,\n) -> nn.Module:\n\n    cfg, weights_path = create_model_config(\n        backbone=backbone,\n        pretrained=pretrained,\n        checkpoints_path=checkpoints_path,\n        force_download=force_download,\n    )\n\n    if model_type == \"one_stage_detector_bbox\":\n        cfg.model.bbox_head.num_classes = num_classes - 1\n\n    if model_type == \"two_stage_detector_bbox\":\n        # Sparse-RCNN has a list of bbox_head whereas Faster-RCNN has only one\n        if isinstance(cfg.model.roi_head.bbox_head, list):\n            for bbox_head in cfg.model.roi_head.bbox_head:\n                bbox_head[\"num_classes\"] = num_classes - 1\n        else:\n            cfg.model.roi_head.bbox_head.num_classes = num_classes - 1\n\n    if model_type == \"two_stage_detector_mask\":\n        cfg.model.roi_head.bbox_head.num_classes = num_classes - 1\n        cfg.model.roi_head.mask_head.num_classes = num_classes - 1\n\n    if (pretrained == False) or (weights_path is not None):\n        cfg.model.pretrained = None\n\n    _model = build_detector(cfg.model, cfg.get(\"train_cfg\"), cfg.get(\"test_cfg\"))\n    _model.init_weights()\n\n    if pretrained and (weights_path is not None):\n        load_checkpoint(_model, str(weights_path))\n\n    _model.param_groups = MethodType(param_groups, _model)\n\n    return _model\n", "path": "icevision/models/mmdet/common/utils.py"}, {"content": "__all__ = [\n    \"MMDetBackboneConfig\",\n    \"mmdet_configs_path\",\n    \"param_groups\",\n    \"MMDetBackboneConfig\",\n    \"create_model_config\",\n]\n\nfrom icevision.imports import *\nfrom icevision.utils import *\nfrom icevision.backbones import BackboneConfig\nfrom icevision.models.mmdet.download_configs import download_mmdet_configs\nfrom mmdet.models.detectors import *\nfrom mmcv import Config\nfrom mmdet.models.backbones.ssd_vgg import SSDVGG\n\n\nmmdet_configs_path = download_mmdet_configs()\n\n\nclass MMDetBackboneConfig(BackboneConfig):\n    def __init__(self, model_name, config_path, weights_url):\n        self.model_name = model_name\n        self.config_path = config_path\n        self.weights_url = weights_url\n        self.pretrained: bool\n\n    def __call__(self, pretrained: bool = True) -> \"MMDetBackboneConfig\":\n        self.pretrained = pretrained\n        return self\n\n\ndef param_groups(model):\n    body = model.backbone\n\n    layers = []\n    if isinstance(body, SSDVGG):\n        layers += [body.features]\n        layers += [body.extra, body.l2_norm]\n    else:\n        layers += [nn.Sequential(body.conv1, body.bn1)]\n        layers += [getattr(body, l) for l in body.res_layers]\n        layers += [model.neck]\n\n    if isinstance(model, SingleStageDetector):\n        layers += [model.bbox_head]\n    elif isinstance(model, TwoStageDetector):\n        layers += [nn.Sequential(model.rpn_head, model.roi_head)]\n    else:\n        raise RuntimeError(\n            \"{model} must inherit either from SingleStageDetector or TwoStageDetector class\"\n        )\n\n    _param_groups = [list(layer.parameters()) for layer in layers]\n    check_all_model_params_in_groups2(model, _param_groups)\n    return _param_groups\n\n\ndef create_model_config(\n    backbone: MMDetBackboneConfig,\n    pretrained: bool = True,\n    checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n    force_download=False,\n):\n\n    model_name = backbone.model_name\n    config_path = backbone.config_path\n    weights_url = backbone.weights_url\n\n    # download weights\n    weights_path = None\n    if pretrained and weights_url:\n        save_dir = Path(checkpoints_path) / model_name\n        save_dir.mkdir(exist_ok=True, parents=True)\n\n        fname = Path(weights_url).name\n        weights_path = save_dir / fname\n\n        if not weights_path.exists() or force_download:\n            download_url(url=weights_url, save_path=str(weights_path))\n\n    cfg = Config.fromfile(config_path)\n\n    return cfg, weights_path\n", "path": "icevision/models/mmdet/utils.py"}, {"content": "__all__ = [\"model\"]\n\nfrom icevision.imports import *\nfrom mmcv import Config\nfrom mmdet.models import build_detector\nfrom mmcv.runner import load_checkpoint\nfrom icevision.models.mmdet.utils import *\nfrom icevision.utils.download_utils import *\nfrom icevision.models.mmdet.common.utils import *\n\n\ndef model(\n    backbone: MMDetBackboneConfig,\n    num_classes: int,\n    checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n    force_download=False,\n) -> nn.Module:\n\n    return build_model(\n        model_type=\"one_stage_detector_bbox\",\n        backbone=backbone,\n        num_classes=num_classes,\n        pretrained=backbone.pretrained,\n        checkpoints_path=checkpoints_path,\n        force_download=force_download,\n    )\n", "path": "icevision/models/mmdet/common/bbox/single_stage/model.py"}], "after_files": [{"content": "__all__ = [\n    \"convert_background_from_zero_to_last\",\n    \"convert_background_from_last_to_zero\",\n    \"mmdet_tensor_to_image\",\n    \"build_model\",\n]\n\nfrom icevision.imports import *\nfrom icevision.utils import *\nfrom mmcv import Config\nfrom mmdet.models import build_detector\nfrom mmcv.runner import load_checkpoint\nfrom icevision.models.mmdet.utils import *\n\n\ndef convert_background_from_zero_to_last(label_ids, class_map):\n    label_ids = label_ids - 1\n    label_ids[label_ids == -1] = class_map.num_classes - 1\n    return label_ids\n\n\ndef convert_background_from_last_to_zero(label_ids, class_map):\n    label_ids = label_ids + 1\n    label_ids[label_ids == len(class_map)] = 0\n    return label_ids\n\n\ndef mmdet_tensor_to_image(tensor_image):\n    return tensor_to_image(tensor_image)[:, :, ::-1].copy()\n\n\ndef build_model(\n    model_type: str,\n    backbone: MMDetBackboneConfig,\n    num_classes: int,\n    pretrained: bool = True,\n    checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n    force_download=False,\n    cfg_options=None,\n) -> nn.Module:\n\n    cfg, weights_path = create_model_config(\n        backbone=backbone,\n        pretrained=pretrained,\n        checkpoints_path=checkpoints_path,\n        force_download=force_download,\n        cfg_options=cfg_options,\n    )\n\n    if model_type == \"one_stage_detector_bbox\":\n        cfg.model.bbox_head.num_classes = num_classes - 1\n\n    if model_type == \"two_stage_detector_bbox\":\n        # Sparse-RCNN has a list of bbox_head whereas Faster-RCNN has only one\n        if isinstance(cfg.model.roi_head.bbox_head, list):\n            for bbox_head in cfg.model.roi_head.bbox_head:\n                bbox_head[\"num_classes\"] = num_classes - 1\n        else:\n            cfg.model.roi_head.bbox_head.num_classes = num_classes - 1\n\n    if model_type == \"two_stage_detector_mask\":\n        cfg.model.roi_head.bbox_head.num_classes = num_classes - 1\n        cfg.model.roi_head.mask_head.num_classes = num_classes - 1\n\n    if (pretrained == False) or (weights_path is not None):\n        cfg.model.pretrained = None\n\n    _model = build_detector(cfg.model, cfg.get(\"train_cfg\"), cfg.get(\"test_cfg\"))\n    _model.init_weights()\n\n    if pretrained and (weights_path is not None):\n        load_checkpoint(_model, str(weights_path))\n\n    _model.param_groups = MethodType(param_groups, _model)\n    _model.cfg = cfg  # save the config in the model for convenience\n    _model.weights_path = weights_path  # save the model.weights_path in case we want to rebuild the model after updating its attributes\n\n    return _model\n", "path": "icevision/models/mmdet/common/utils.py"}, {"content": "__all__ = [\n    \"MMDetBackboneConfig\",\n    \"mmdet_configs_path\",\n    \"param_groups\",\n    \"MMDetBackboneConfig\",\n    \"create_model_config\",\n]\n\nfrom icevision.imports import *\nfrom icevision.utils import *\nfrom icevision.backbones import BackboneConfig\nfrom icevision.models.mmdet.download_configs import download_mmdet_configs\nfrom mmdet.models.detectors import *\nfrom mmcv import Config\nfrom mmdet.models.backbones.ssd_vgg import SSDVGG\n\n\nmmdet_configs_path = download_mmdet_configs()\n\n\nclass MMDetBackboneConfig(BackboneConfig):\n    def __init__(self, model_name, config_path, weights_url):\n        self.model_name = model_name\n        self.config_path = config_path\n        self.weights_url = weights_url\n        self.pretrained: bool\n\n    def __call__(self, pretrained: bool = True) -> \"MMDetBackboneConfig\":\n        self.pretrained = pretrained\n        return self\n\n\ndef param_groups(model):\n    body = model.backbone\n\n    layers = []\n    if isinstance(body, SSDVGG):\n        layers += [body.features]\n        layers += [body.extra, body.l2_norm]\n    else:\n        layers += [nn.Sequential(body.conv1, body.bn1)]\n        layers += [getattr(body, l) for l in body.res_layers]\n        layers += [model.neck]\n\n    if isinstance(model, SingleStageDetector):\n        layers += [model.bbox_head]\n    elif isinstance(model, TwoStageDetector):\n        layers += [nn.Sequential(model.rpn_head, model.roi_head)]\n    else:\n        raise RuntimeError(\n            \"{model} must inherit either from SingleStageDetector or TwoStageDetector class\"\n        )\n\n    _param_groups = [list(layer.parameters()) for layer in layers]\n    check_all_model_params_in_groups2(model, _param_groups)\n    return _param_groups\n\n\ndef create_model_config(\n    backbone: MMDetBackboneConfig,\n    pretrained: bool = True,\n    checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n    force_download=False,\n    cfg_options=None,\n):\n\n    model_name = backbone.model_name\n    config_path = backbone.config_path\n    weights_url = backbone.weights_url\n\n    # download weights\n    weights_path = None\n    if pretrained and weights_url:\n        save_dir = Path(checkpoints_path) / model_name\n        save_dir.mkdir(exist_ok=True, parents=True)\n\n        fname = Path(weights_url).name\n        weights_path = save_dir / fname\n\n        if not weights_path.exists() or force_download:\n            download_url(url=weights_url, save_path=str(weights_path))\n\n    cfg = Config.fromfile(config_path)\n\n    if cfg_options is not None:\n        cfg.merge_from_dict(cfg_options)\n\n    return cfg, weights_path\n", "path": "icevision/models/mmdet/utils.py"}, {"content": "__all__ = [\"model\"]\n\nfrom icevision.imports import *\nfrom mmcv import Config\nfrom mmdet.models import build_detector\nfrom mmcv.runner import load_checkpoint\nfrom icevision.models.mmdet.utils import *\nfrom icevision.utils.download_utils import *\nfrom icevision.models.mmdet.common.utils import *\n\n\ndef model(\n    backbone: MMDetBackboneConfig,\n    num_classes: int,\n    checkpoints_path: Optional[Union[str, Path]] = \"checkpoints\",\n    force_download=False,\n    cfg_options=None,\n) -> nn.Module:\n\n    return build_model(\n        model_type=\"one_stage_detector_bbox\",\n        backbone=backbone,\n        num_classes=num_classes,\n        pretrained=backbone.pretrained,\n        checkpoints_path=checkpoints_path,\n        force_download=force_download,\n        cfg_options=cfg_options,\n    )\n", "path": "icevision/models/mmdet/common/bbox/single_stage/model.py"}]}