class_docstr: Anchor-based head (RPN, RetinaNet, SSD, etc.).
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      feat_channels (int): Number of hidden channels. Used in child classes.
      anchor_generator (dict): Config dict for anchor generator
      bbox_coder (dict): Config of bounding box coder.
      reg_decoded_bbox (bool): If true, the regression loss would be
          applied on decoded bounding boxes. Default: False
      loss_cls (dict): Config of classification loss.
      loss_bbox (dict): Config of localization loss.
      train_cfg (dict): Training config of anchor head.
      test_cfg (dict): Testing config of anchor head.
docstr: Transform network output for a batch into bbox predictions.
  
  Args:
      cls_scores (list[Tensor]): Box scores for each scale level
          Has shape (N, num_anchors * num_classes, H, W)
      bbox_preds (list[Tensor]): Box energies / deltas for each scale
          level with shape (N, num_anchors * 4, H, W)
      img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      cfg (mmcv.Config | None): Test / postprocessing configuration,
          if None, test_cfg would be used
      rescale (bool): If True, return boxes in original image space.
          Default: False.
      with_nms (bool): If True, do nms before return boxes.
          Default: True.
  
  Returns:
      list[tuple[Tensor, Tensor]]: Each item in result_list is 2-tuple.
          The first item is an (n, 5) tensor, where the first 4 columns
          are bounding box positions (tl_x, tl_y, br_x, br_y) and the
          5-th column is a score between 0 and 1. The second item is a
          (n,) tensor where each item is the predicted class labelof the
          corresponding box.
  
  Example:
      >>> import mmcv
      >>> self = AnchorHead(
      >>>     num_classes=9,
      >>>     in_channels=1,
      >>>     anchor_generator=dict(
      >>>         type='AnchorGenerator',
      >>>         scales=[8],
      >>>         ratios=[0.5, 1.0, 2.0],
      >>>         strides=[4,]))
      >>> img_metas = [{'img_shape': (32, 32, 3), 'scale_factor': 1}]
      >>> cfg = mmcv.Config(dict(
      >>>     score_thr=0.00,
      >>>     nms=dict(type='nms', iou_thr=1.0),
      >>>     max_per_img=10))
      >>> feat = torch.rand(1, 1, 3, 3)
      >>> cls_score, bbox_pred = self.forward_single(feat)
      >>> # note the input lists are over different levels, not images
      >>> cls_scores, bbox_preds = [cls_score], [bbox_pred]
      >>> result_list = self.get_bboxes(cls_scores, bbox_preds,
      >>>                               img_metas, cfg)
      >>> det_bboxes, det_labels = result_list[0]
      >>> assert len(result_list) == 1
      >>> assert det_bboxes.shape[1] == 5
      >>> assert len(det_bboxes) == len(det_labels) == cfg.max_per_img
docstr_tok: ["Transform","network","output","for","a","batch","into","bbox","predictions",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","for","each","scale","level","Has","shape","(","N",",","num_anchors","*","num_classes",",","H",",","W",")","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","each","scale","level","with","shape","(","N",",","num_anchors","*","4",",","H",",","W",")","img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","cfg","(","mmcv.Config","|","None",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Default",":","False",".","with_nms","(","bool",")",":","If","True",",","do","nms","before","return","boxes",".","Default",":","True",".","Returns",":","list","[","tuple","[","Tensor",",","Tensor","]","]",":","Each","item","in","result_list","is","2-tuple",".","The","first","item","is","an","(","n",",","5",")","tensor",",","where","the","first","4","columns","are","bounding","box","positions","(","tl_x",",","tl_y",",","br_x",",","br_y",")","and","the","5-th","column","is","a","score","between","0","and","1",".","The","second","item","is","a","(","n",",",")","tensor","where","each","item","is","the","predicted","class","labelof","the","corresponding","box",".","Example",":",">",">",">","import","mmcv",">",">",">","self","=","AnchorHead","(",">",">",">","num_classes=9",",",">",">",">","in_channels=1",",",">",">",">","anchor_generator=dict","(",">",">",">","type='AnchorGenerator","'",",",">",">",">","scales=","[","8","]",",",">",">",">","ratios=","[","0.5",",","1.0",",","2.0","]",",",">",">",">","strides=","[","4",",","]",")",")",">",">",">","img_metas","=","[","{","'img_shape","'",":","(","32",",","32",",","3",")",",","'scale_factor","'",":","1","}","]",">",">",">","cfg","=","mmcv.Config","(","dict","(",">",">",">","score_thr=0.00",",",">",">",">","nms=dict","(","type='nms","'",",","iou_thr=1.0",")",",",">",">",">","max_per_img=10",")",")",">",">",">","feat","=","torch.rand","(","1",",","1",",","3",",","3",")",">",">",">","cls_score",",","bbox_pred","=","self.forward_single","(","feat",")",">",">",">","#","note","the","input","lists","are","over","different","levels",",","not","images",">",">",">","cls_scores",",","bbox_preds","=","[","cls_score","]",",","[","bbox_pred","]",">",">",">","result_list","=","self.get_bboxes","(","cls_scores",",","bbox_preds",",",">",">",">","img_metas",",","cfg",")",">",">",">","det_bboxes",",","det_labels","=","result_list","[","0","]",">",">",">","assert","len","(","result_list",")","==","1",">",">",">","assert","det_bboxes.shape","[","1","]","==","5",">",">",">","assert","len","(","det_bboxes",")","==","len","(","det_labels",")","==","cfg.max_per_img"]
code: def get_bboxes(
      self,
      cls_scores,
      bbox_preds,
      img_metas,
      cfg=None,
      rescale=False,
      with_nms=True,
  ):
      """Transform network output for a batch into bbox predictions.
  
      Args:
          cls_scores (list[Tensor]): Box scores for each scale level
              Has shape (N, num_anchors * num_classes, H, W)
          bbox_preds (list[Tensor]): Box energies / deltas for each scale
              level with shape (N, num_anchors * 4, H, W)
          img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          cfg (mmcv.Config | None): Test / postprocessing configuration,
              if None, test_cfg would be used
          rescale (bool): If True, return boxes in original image space.
              Default: False.
          with_nms (bool): If True, do nms before return boxes.
              Default: True.
  
      Returns:
          list[tuple[Tensor, Tensor]]: Each item in result_list is 2-tuple.
              The first item is an (n, 5) tensor, where the first 4 columns
              are bounding box positions (tl_x, tl_y, br_x, br_y) and the
              5-th column is a score between 0 and 1. The second item is a
              (n,) tensor where each item is the predicted class labelof the
              corresponding box.
  
      Example:
          >>> import mmcv
          >>> self = AnchorHead(
          >>>     num_classes=9,
          >>>     in_channels=1,
          >>>     anchor_generator=dict(
          >>>         type='AnchorGenerator',
          >>>         scales=[8],
          >>>         ratios=[0.5, 1.0, 2.0],
          >>>         strides=[4,]))
          >>> img_metas = [{'img_shape': (32, 32, 3), 'scale_factor': 1}]
          >>> cfg = mmcv.Config(dict(
          >>>     score_thr=0.00,
          >>>     nms=dict(type='nms', iou_thr=1.0),
          >>>     max_per_img=10))
          >>> feat = torch.rand(1, 1, 3, 3)
          >>> cls_score, bbox_pred = self.forward_single(feat)
          >>> # note the input lists are over different levels, not images
          >>> cls_scores, bbox_preds = [cls_score], [bbox_pred]
          >>> result_list = self.get_bboxes(cls_scores, bbox_preds,
          >>>                               img_metas, cfg)
          >>> det_bboxes, det_labels = result_list[0]
          >>> assert len(result_list) == 1
          >>> assert det_bboxes.shape[1] == 5
          >>> assert len(det_bboxes) == len(det_labels) == cfg.max_per_img
      """
      assert len(cls_scores) == len(bbox_preds)
      num_levels = len(cls_scores)
  
      device = cls_scores[0].device
      featmap_sizes = [
          cls_scores[i].shape[-2:] for i in range(num_levels)
      ]
      mlvl_anchors = self.anchor_generator.grid_anchors(
          featmap_sizes, device=device
      )
  
      result_list = []
      for img_id in range(len(img_metas)):
          cls_score_list = [
              cls_scores[i][img_id].detach() for i in range(num_levels)
          ]
          bbox_pred_list = [
              bbox_preds[i][img_id].detach() for i in range(num_levels)
          ]
          img_shape = img_metas[img_id]["img_shape"]
          scale_factor = img_metas[img_id]["scale_factor"]
          if with_nms:
              # some heads don't support with_nms argument
              proposals = self._get_bboxes_single(
                  cls_score_list,
                  bbox_pred_list,
                  mlvl_anchors,
                  img_shape,
                  scale_factor,
                  cfg,
                  rescale,
              )
          else:
              proposals = self._get_bboxes_single(
                  cls_score_list,
                  bbox_pred_list,
                  mlvl_anchors,
                  img_shape,
                  scale_factor,
                  cfg,
                  rescale,
                  with_nms,
              )
          result_list.append(proposals)
      return result_list
  
imports: import torch
  import torch.nn
  from mmcv.cnn import normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, build_anchor_generator, build_assigner, build_bbox_coder, build_sampler, images_to_levels, multi_apply, multiclass_nms, unmap
  from ..builder import HEADS, build_loss
  from .base_dense_head import BaseDenseHead
  from .dense_test_mixins import BBoxTestMixin
label_desc: Use image node_id 11 for calling the AnchorHead obj's underlying member method code with example usage: obj.get_bboxes(cls_scores, bbox_preds, img_metas, cfg, rescale, with_nms) and returns: result_list