class_docstr: Wrapper of mmdetection backbones to use in detectron2.
  
  mmdet backbones produce list/tuple of tensors, while detectron2 backbones
  produce a dict of tensors. This class wraps the given backbone to produce
  output in detectron2's convention, so it can be used in place of detectron2
  backbones.
class_docstr_tok: ["Wrapper","of","mmdetection","backbones","to","use","in","detectron2",".","mmdet","backbones","produce","list\/tuple","of","tensors",",","while","detectron2","backbones","produce","a","dict","of","tensors",".","This","class","wraps","the","given","backbone","to","produce","output","in","detectron2","'s","convention",",","so","it","can","be","used","in","place","of","detectron2","backbones","."]
docstr: Args:
      backbone: either a backbone module or a mmdet config dict that defines a
          backbone. The backbone takes a 4D image tensor and returns a
          sequence of tensors.
      neck: either a backbone module or a mmdet config dict that defines a
          neck. The neck takes outputs of backbone and returns a
          sequence of tensors. If None, no neck is used.
      output_shapes: shape for every output of the backbone (or neck, if given).
          stride and channels are often needed.
      output_names: names for every output of the backbone (or neck, if given).
          By default, will use "out0", "out1", ...
docstr_tok: ["Args",":","backbone",":","either","a","backbone","module","or","a","mmdet","config","dict","that","defines","a","backbone",".","The","backbone","takes","a","4D","image","tensor","and","returns","a","sequence","of","tensors",".","neck",":","either","a","backbone","module","or","a","mmdet","config","dict","that","defines","a","neck",".","The","neck","takes","outputs","of","backbone","and","returns","a","sequence","of","tensors",".","If","None",",","no","neck","is","used",".","output_shapes",":","shape","for","every","output","of","the","backbone","(","or","neck",",","if","given",")",".","stride","and","channels","are","often","needed",".","output_names",":","names","for","every","output","of","the","backbone","(","or","neck",",","if","given",")",".","By","default",",","will","use","``","out0","''",",","``","out1","''",",","..."]
code: def __init__(
      self,
      backbone: Union[nn.Module, Mapping],
      neck: Union[nn.Module, Mapping, None] = None,
      *,
      output_shapes: List[ShapeSpec],
      output_names: Optional[List[str]] = None,
  ):
      """
      Args:
          backbone: either a backbone module or a mmdet config dict that defines a
              backbone. The backbone takes a 4D image tensor and returns a
              sequence of tensors.
          neck: either a backbone module or a mmdet config dict that defines a
              neck. The neck takes outputs of backbone and returns a
              sequence of tensors. If None, no neck is used.
          output_shapes: shape for every output of the backbone (or neck, if given).
              stride and channels are often needed.
          output_names: names for every output of the backbone (or neck, if given).
              By default, will use "out0", "out1", ...
      """
      super().__init__()
      if isinstance(backbone, Mapping):
          from mmdet.models import build_backbone
  
          backbone = build_backbone(_to_container(backbone))
      self.backbone = backbone
  
      if isinstance(neck, Mapping):
          from mmdet.models import build_neck
  
          neck = build_neck(_to_container(neck))
      self.neck = neck
  
      # "Neck" weights, if any, are part of neck itself. This is the interface
      # of mmdet so we follow it. Reference:
      # https://github.com/open-mmlab/mmdetection/blob/master/mmdet/models/detectors/two_stage.py
      logger.info("Initializing mmdet backbone weights...")
      self.backbone.init_weights()
      # train() in mmdet modules is non-trivial, and has to be explicitly
      # called. Reference:
      # https://github.com/open-mmlab/mmdetection/blob/master/mmdet/models/backbones/resnet.py
      self.backbone.train()
      if self.neck is not None:
          logger.info("Initializing mmdet neck weights ...")
          if isinstance(self.neck, nn.Sequential):
              for m in self.neck:
                  m.init_weights()
          else:
              self.neck.init_weights()
          self.neck.train()
  
      self._output_shapes = output_shapes
      if not output_names:
          output_names = [f"out{i}" for i in range(len(output_shapes))]
      self._output_names = output_names
  
imports: import itertools
  import logging
  import numpy
  from collections import OrderedDict
  from collections.abc import Mapping
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from omegaconf import DictConfig, OmegaConf
  from torch import Tensor, nn
  from detectron2.layers import ShapeSpec
  from detectron2.structures import BitMasks, Boxes, ImageList, Instances
  from detectron2.utils.events import get_event_storage
  from .backbone import Backbone
label_desc: Use image node_id 1 to create a new MMDetBackbone object from inherited base classes: Backbone with example: obj = MMDetBackbone(backbone, neck)