prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  SSD model doesn't work
  ## 🐛 Bug
  
  SSD model doesn't work anymore. It seems related to MMDetection updates made here:
  https://github.com/open-mmlab/mmdetection/pull/5789/files
  
  Refer to discussion on our Discord forum:
  https://discord.com/channels/735877944085446747/780951885485965352/920249646964670464
  
  --- 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/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 from mmdet.models.backbones.csp_darknet import CSPDarknet
  17 
  18 
  19 mmdet_configs_path = download_mmdet_configs()
  20 
  21 
  22 class MMDetBackboneConfig(BackboneConfig):
  23     def __init__(self, model_name, config_path, weights_url):
  24         self.model_name = model_name
  25         self.config_path = config_path
  26         self.weights_url = weights_url
  27         self.pretrained: bool
  28 
  29     def __call__(self, pretrained: bool = True) -> "MMDetBackboneConfig":
  30         self.pretrained = pretrained
  31         return self
  32 
  33 
  34 def param_groups(model):
  35     body = model.backbone
  36 
  37     layers = []
  38     if isinstance(body, SSDVGG):
  39         layers += [body.features]
  40         layers += [body.extra, body.l2_norm]
  41     elif isinstance(body, CSPDarknet):
  42         layers += [body.stem.conv.conv, body.stem.conv.bn]
  43         layers += [body.stage1, body.stage2, body.stage3, body.stage4]
  44         layers += [model.neck]
  45     else:
  46         layers += [nn.Sequential(body.conv1, body.bn1)]
  47         layers += [getattr(body, l) for l in body.res_layers]
  48         layers += [model.neck]
  49 
  50     if isinstance(model, SingleStageDetector):
  51         layers += [model.bbox_head]
  52     elif isinstance(model, TwoStageDetector):
  53         layers += [nn.Sequential(model.rpn_head, model.roi_head)]
  54     else:
  55         raise RuntimeError(
  56             "{model} must inherit either from SingleStageDetector or TwoStageDetector class"
  57         )
  58 
  59     _param_groups = [list(layer.parameters()) for layer in layers]
  60     check_all_model_params_in_groups2(model, _param_groups)
  61     return _param_groups
  62 
  63 
  64 def create_model_config(
  65     backbone: MMDetBackboneConfig,
  66     pretrained: bool = True,
  67     checkpoints_path: Optional[Union[str, Path]] = "checkpoints",
  68     force_download=False,
  69     cfg_options=None,
  70 ):
  71 
  72     model_name = backbone.model_name
  73     config_path = backbone.config_path
  74     weights_url = backbone.weights_url
  75 
  76     # download weights
  77     weights_path = None
  78     if pretrained and weights_url:
  79         save_dir = Path(checkpoints_path) / model_name
  80         save_dir.mkdir(exist_ok=True, parents=True)
  81 
  82         fname = Path(weights_url).name
  83         weights_path = save_dir / fname
  84 
  85         if not weights_path.exists() or force_download:
  86             download_url(url=weights_url, save_path=str(weights_path))
  87 
  88     cfg = Config.fromfile(config_path)
  89 
  90     if cfg_options is not None:
  91         cfg.merge_from_dict(cfg_options)
  92 
  93     return cfg, weights_path
  94
  ```
  
  Path: `icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py`
  Content:
  ```
  1 __all__ = [
  2     "ssd300",
  3     "ssd512",
  4 ]
  5 
  6 from icevision.imports import *
  7 from icevision.models.mmdet.utils import *
  8 
  9 
  10 class MMDetSSDBackboneConfig(MMDetBackboneConfig):
  11     def __init__(self, **kwargs):
  12         super().__init__(model_name="ssd", **kwargs)
  13 
  14 
  15 base_config_path = mmdet_configs_path / "ssd"
  16 base_weights_url = "http://download.openmmlab.com/mmdetection/v2.0/ssd"
  17 
  18 ssd300 = MMDetSSDBackboneConfig(
  19     config_path=base_config_path / "ssd300_coco.py",
  20     weights_url=f"{base_weights_url}/ssd300_coco/ssd300_coco_20200307-a92d2092.pth",
  21 )
  22 
  23 ssd512 = MMDetSSDBackboneConfig(
  24     config_path=base_config_path / "ssd512_coco.py",
  25     weights_url=f"{base_weights_url}/ssd512_coco/ssd512_coco_20200308-038c5591.pth",
  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/models/ssd/backbones/resnet_fpn.py b/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py
  --- a/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py
  +++ b/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py
  @@ -1,6 +1,7 @@
   __all__ = [
       "ssd300",
       "ssd512",
  +    "ssdlite_mobilenetv2",
   ]
   
   from icevision.imports import *
  @@ -17,10 +18,15 @@
   
   ssd300 = MMDetSSDBackboneConfig(
       config_path=base_config_path / "ssd300_coco.py",
  -    weights_url=f"{base_weights_url}/ssd300_coco/ssd300_coco_20200307-a92d2092.pth",
  +    weights_url=f"{base_weights_url}/ssd300_coco/ssd300_coco_20210803_015428-d231a06e.pth",
   )
   
   ssd512 = MMDetSSDBackboneConfig(
       config_path=base_config_path / "ssd512_coco.py",
  -    weights_url=f"{base_weights_url}/ssd512_coco/ssd512_coco_20200308-038c5591.pth",
  +    weights_url=f"{base_weights_url}/ssd512_coco/ssd512_coco_20210803_022849-0a47a1ca.pth",
  +)
  +
  +ssdlite_mobilenetv2 = MMDetSSDBackboneConfig(
  +    config_path=base_config_path / "ssdlite_mobilenetv2_scratch_600e_coco.py",
  +    weights_url=f"{base_weights_url}/ssd512_coco/ssdlite_mobilenetv2_scratch_600e_coco_20210629_110627-974d9307.pth",
   )
  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
  @@ -35,18 +35,21 @@
       body = model.backbone
   
       layers = []
  +
  +    # add the backbone
       if isinstance(body, SSDVGG):
           layers += [body.features]
  -        layers += [body.extra, body.l2_norm]
       elif isinstance(body, CSPDarknet):
           layers += [body.stem.conv.conv, body.stem.conv.bn]
           layers += [body.stage1, body.stage2, body.stage3, body.stage4]
  -        layers += [model.neck]
       else:
           layers += [nn.Sequential(body.conv1, body.bn1)]
           layers += [getattr(body, l) for l in body.res_layers]
  -        layers += [model.neck]
   
  +    # add the neck
  +    layers += [model.neck]
  +
  +    # add the head
       if isinstance(model, SingleStageDetector):
           layers += [model.bbox_head]
       elif isinstance(model, TwoStageDetector):
  
verification_info: {"golden_diff": "diff --git a/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py b/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py\n--- a/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py\n+++ b/icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py\n@@ -1,6 +1,7 @@\n __all__ = [\n     \"ssd300\",\n     \"ssd512\",\n+    \"ssdlite_mobilenetv2\",\n ]\n \n from icevision.imports import *\n@@ -17,10 +18,15 @@\n \n ssd300 = MMDetSSDBackboneConfig(\n     config_path=base_config_path / \"ssd300_coco.py\",\n-    weights_url=f\"{base_weights_url}/ssd300_coco/ssd300_coco_20200307-a92d2092.pth\",\n+    weights_url=f\"{base_weights_url}/ssd300_coco/ssd300_coco_20210803_015428-d231a06e.pth\",\n )\n \n ssd512 = MMDetSSDBackboneConfig(\n     config_path=base_config_path / \"ssd512_coco.py\",\n-    weights_url=f\"{base_weights_url}/ssd512_coco/ssd512_coco_20200308-038c5591.pth\",\n+    weights_url=f\"{base_weights_url}/ssd512_coco/ssd512_coco_20210803_022849-0a47a1ca.pth\",\n+)\n+\n+ssdlite_mobilenetv2 = MMDetSSDBackboneConfig(\n+    config_path=base_config_path / \"ssdlite_mobilenetv2_scratch_600e_coco.py\",\n+    weights_url=f\"{base_weights_url}/ssd512_coco/ssdlite_mobilenetv2_scratch_600e_coco_20210629_110627-974d9307.pth\",\n )\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@@ -35,18 +35,21 @@\n     body = model.backbone\n \n     layers = []\n+\n+    # add the backbone\n     if isinstance(body, SSDVGG):\n         layers += [body.features]\n-        layers += [body.extra, body.l2_norm]\n     elif isinstance(body, CSPDarknet):\n         layers += [body.stem.conv.conv, body.stem.conv.bn]\n         layers += [body.stage1, body.stage2, body.stage3, body.stage4]\n-        layers += [model.neck]\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+    # add the neck\n+    layers += [model.neck]\n+\n+    # add the head\n     if isinstance(model, SingleStageDetector):\n         layers += [model.bbox_head]\n     elif isinstance(model, TwoStageDetector):\n", "issue": "SSD model doesn't work\n## \ud83d\udc1b Bug\r\n\r\nSSD model doesn't work anymore. It seems related to MMDetection updates made here:\r\nhttps://github.com/open-mmlab/mmdetection/pull/5789/files\r\n\r\nRefer to discussion on our Discord forum:\r\nhttps://discord.com/channels/735877944085446747/780951885485965352/920249646964670464\n", "before_files": [{"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\nfrom mmdet.models.backbones.csp_darknet import CSPDarknet\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    elif isinstance(body, CSPDarknet):\n        layers += [body.stem.conv.conv, body.stem.conv.bn]\n        layers += [body.stage1, body.stage2, body.stage3, body.stage4]\n        layers += [model.neck]\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__ = [\n    \"ssd300\",\n    \"ssd512\",\n]\n\nfrom icevision.imports import *\nfrom icevision.models.mmdet.utils import *\n\n\nclass MMDetSSDBackboneConfig(MMDetBackboneConfig):\n    def __init__(self, **kwargs):\n        super().__init__(model_name=\"ssd\", **kwargs)\n\n\nbase_config_path = mmdet_configs_path / \"ssd\"\nbase_weights_url = \"http://download.openmmlab.com/mmdetection/v2.0/ssd\"\n\nssd300 = MMDetSSDBackboneConfig(\n    config_path=base_config_path / \"ssd300_coco.py\",\n    weights_url=f\"{base_weights_url}/ssd300_coco/ssd300_coco_20200307-a92d2092.pth\",\n)\n\nssd512 = MMDetSSDBackboneConfig(\n    config_path=base_config_path / \"ssd512_coco.py\",\n    weights_url=f\"{base_weights_url}/ssd512_coco/ssd512_coco_20200308-038c5591.pth\",\n)\n", "path": "icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py"}], "after_files": [{"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\nfrom mmdet.models.backbones.csp_darknet import CSPDarknet\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\n    # add the backbone\n    if isinstance(body, SSDVGG):\n        layers += [body.features]\n    elif isinstance(body, CSPDarknet):\n        layers += [body.stem.conv.conv, body.stem.conv.bn]\n        layers += [body.stage1, body.stage2, body.stage3, body.stage4]\n    else:\n        layers += [nn.Sequential(body.conv1, body.bn1)]\n        layers += [getattr(body, l) for l in body.res_layers]\n\n    # add the neck\n    layers += [model.neck]\n\n    # add the head\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__ = [\n    \"ssd300\",\n    \"ssd512\",\n    \"ssdlite_mobilenetv2\",\n]\n\nfrom icevision.imports import *\nfrom icevision.models.mmdet.utils import *\n\n\nclass MMDetSSDBackboneConfig(MMDetBackboneConfig):\n    def __init__(self, **kwargs):\n        super().__init__(model_name=\"ssd\", **kwargs)\n\n\nbase_config_path = mmdet_configs_path / \"ssd\"\nbase_weights_url = \"http://download.openmmlab.com/mmdetection/v2.0/ssd\"\n\nssd300 = MMDetSSDBackboneConfig(\n    config_path=base_config_path / \"ssd300_coco.py\",\n    weights_url=f\"{base_weights_url}/ssd300_coco/ssd300_coco_20210803_015428-d231a06e.pth\",\n)\n\nssd512 = MMDetSSDBackboneConfig(\n    config_path=base_config_path / \"ssd512_coco.py\",\n    weights_url=f\"{base_weights_url}/ssd512_coco/ssd512_coco_20210803_022849-0a47a1ca.pth\",\n)\n\nssdlite_mobilenetv2 = MMDetSSDBackboneConfig(\n    config_path=base_config_path / \"ssdlite_mobilenetv2_scratch_600e_coco.py\",\n    weights_url=f\"{base_weights_url}/ssd512_coco/ssdlite_mobilenetv2_scratch_600e_coco_20210629_110627-974d9307.pth\",\n)\n", "path": "icevision/models/mmdet/models/ssd/backbones/resnet_fpn.py"}]}