class_docstr: YOLOV3Head Paper link: https://arxiv.org/abs/1804.02767.
  
  Args:
      num_classes (int): The number of object classes (w/o background)
      in_channels (List[int]): Number of input channels per scale.
      out_channels (List[int]): The number of output channels per scale
          before the final 1x1 layer. Default: (1024, 512, 256).
      anchor_generator (dict): Config dict for anchor generator
      bbox_coder (dict): Config of bounding box coder.
      featmap_strides (List[int]): The stride of each scale.
          Should be in descending order. Default: (32, 16, 8).
      one_hot_smoother (float): Set a non-zero value to enable label-smooth
          Default: 0.
      conv_cfg (dict): Config dict for convolution layer. Default: None.
      norm_cfg (dict): Dictionary to construct and config norm layer.
          Default: dict(type='BN', requires_grad=True)
      act_cfg (dict): Config dict for activation layer.
          Default: dict(type='LeakyReLU', negative_slope=0.1).
      loss_cls (dict): Config of classification loss.
      loss_conf (dict): Config of confidence loss.
      loss_xy (dict): Config of xy coordinate loss.
      loss_wh (dict): Config of wh coordinate loss.
      train_cfg (dict): Training config of YOLOV3 head. Default: None.
      test_cfg (dict): Testing config of YOLOV3 head. Default: None.
class_docstr_tok: ["YOLOV3Head","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1804.02767",".","Args",":","num_classes","(","int",")",":","The","number","of","object","classes","(","w\/o","background",")","in_channels","(","List","[","int","]",")",":","Number","of","input","channels","per","scale",".","out_channels","(","List","[","int","]",")",":","The","number","of","output","channels","per","scale","before","the","final","1x1","layer",".","Default",":","(","1024",",","512",",","256",")",".","anchor_generator","(","dict",")",":","Config","dict","for","anchor","generator","bbox_coder","(","dict",")",":","Config","of","bounding","box","coder",".","featmap_strides","(","List","[","int","]",")",":","The","stride","of","each","scale",".","Should","be","in","descending","order",".","Default",":","(","32",",","16",",","8",")",".","one_hot_smoother","(","float",")",":","Set","a","non-zero","value","to","enable","label-smooth","Default",":","0.","conv_cfg","(","dict",")",":","Config","dict","for","convolution","layer",".","Default",":","None",".","norm_cfg","(","dict",")",":","Dictionary","to","construct","and","config","norm","layer",".","Default",":","dict","(","type='BN","'",",","requires_grad=True",")","act_cfg","(","dict",")",":","Config","dict","for","activation","layer",".","Default",":","dict","(","type='LeakyReLU","'",",","negative_slope=0.1",")",".","loss_cls","(","dict",")",":","Config","of","classification","loss",".","loss_conf","(","dict",")",":","Config","of","confidence","loss",".","loss_xy","(","dict",")",":","Config","of","xy","coordinate","loss",".","loss_wh","(","dict",")",":","Config","of","wh","coordinate","loss",".","train_cfg","(","dict",")",":","Training","config","of","YOLOV3","head",".","Default",":","None",".","test_cfg","(","dict",")",":","Testing","config","of","YOLOV3","head",".","Default",":","None","."]
docstr: Transform outputs for a single batch item into bbox predictions.
  
  Args:
      pred_maps_list (list[Tensor]): Prediction maps for different scales
          of each single image in the batch.
      scale_factor (ndarray): Scale factor of the image arrange as
          (w_scale, h_scale, w_scale, h_scale).
      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:
      tuple(Tensor):
          det_bboxes (Tensor): BBox predictions in shape (n, 5), 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.
          det_labels (Tensor): A (n,) tensor where each item is the
              predicted class label of the corresponding box.
docstr_tok: ["Transform","outputs","for","a","single","batch","item","into","bbox","predictions",".","Args",":","pred_maps_list","(","list","[","Tensor","]",")",":","Prediction","maps","for","different","scales","of","each","single","image","in","the","batch",".","scale_factor","(","ndarray",")",":","Scale","factor","of","the","image","arrange","as","(","w_scale",",","h_scale",",","w_scale",",","h_scale",")",".","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",":","tuple","(","Tensor",")",":","det_bboxes","(","Tensor",")",":","BBox","predictions","in","shape","(","n",",","5",")",",","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.","det_labels","(","Tensor",")",":","A","(","n",",",")","tensor","where","each","item","is","the","predicted","class","label","of","the","corresponding","box","."]
code: def _get_bboxes_single(
      self,
      pred_maps_list,
      scale_factor,
      cfg,
      rescale=False,
      with_nms=True,
  ):
      """Transform outputs for a single batch item into bbox predictions.
  
      Args:
          pred_maps_list (list[Tensor]): Prediction maps for different scales
              of each single image in the batch.
          scale_factor (ndarray): Scale factor of the image arrange as
              (w_scale, h_scale, w_scale, h_scale).
          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:
          tuple(Tensor):
              det_bboxes (Tensor): BBox predictions in shape (n, 5), 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.
              det_labels (Tensor): A (n,) tensor where each item is the
                  predicted class label of the corresponding box.
      """
      cfg = self.test_cfg if cfg is None else cfg
      assert len(pred_maps_list) == self.num_levels
      multi_lvl_bboxes = []
      multi_lvl_cls_scores = []
      multi_lvl_conf_scores = []
      num_levels = len(pred_maps_list)
      featmap_sizes = [
          pred_maps_list[i].shape[-2:] for i in range(num_levels)
      ]
      multi_lvl_anchors = self.anchor_generator.grid_anchors(
          featmap_sizes, pred_maps_list[0][0].device
      )
      for i in range(self.num_levels):
          # get some key info for current scale
          pred_map = pred_maps_list[i]
          stride = self.featmap_strides[i]
  
          # (h, w, num_anchors*num_attrib) -> (h*w*num_anchors, num_attrib)
          pred_map = pred_map.permute(1, 2, 0).reshape(
              -1, self.num_attrib
          )
  
          pred_map[..., :2] = torch.sigmoid(pred_map[..., :2])
          bbox_pred = self.bbox_coder.decode(
              multi_lvl_anchors[i], pred_map[..., :4], stride
          )
          # conf and cls
          conf_pred = torch.sigmoid(pred_map[..., 4]).view(-1)
          cls_pred = torch.sigmoid(pred_map[..., 5:]).view(
              -1, self.num_classes
          )  # Cls pred one-hot.
  
          # Filtering out all predictions with conf < conf_thr
          conf_thr = cfg.get("conf_thr", -1)
          if conf_thr > 0:
              # add as_tuple=False for compatibility in Pytorch 1.6
              # flatten would create a Reshape op with constant values,
              # and raise RuntimeError when doing inference in ONNX Runtime
              # with a different input image (#4221).
              conf_inds = (
                  conf_pred.ge(conf_thr)
                  .nonzero(as_tuple=False)
                  .squeeze(1)
              )
              bbox_pred = bbox_pred[conf_inds, :]
              cls_pred = cls_pred[conf_inds, :]
              conf_pred = conf_pred[conf_inds]
  
          # Get top-k prediction
          nms_pre = cfg.get("nms_pre", -1)
          if 0 < nms_pre < conf_pred.size(0) and (
              not torch.onnx.is_in_onnx_export()
          ):
              _, topk_inds = conf_pred.topk(nms_pre)
              bbox_pred = bbox_pred[topk_inds, :]
              cls_pred = cls_pred[topk_inds, :]
              conf_pred = conf_pred[topk_inds]
  
          # Save the result of current scale
          multi_lvl_bboxes.append(bbox_pred)
          multi_lvl_cls_scores.append(cls_pred)
          multi_lvl_conf_scores.append(conf_pred)
  
      # Merge the results of different scales together
      multi_lvl_bboxes = torch.cat(multi_lvl_bboxes)
      multi_lvl_cls_scores = torch.cat(multi_lvl_cls_scores)
      multi_lvl_conf_scores = torch.cat(multi_lvl_conf_scores)
  
      if with_nms and (multi_lvl_conf_scores.size(0) == 0):
          return torch.zeros((0, 5)), torch.zeros((0,))
  
      if rescale:
          multi_lvl_bboxes /= multi_lvl_bboxes.new_tensor(scale_factor)
  
      # In mmdet 2.x, the class_id for background is num_classes.
      # i.e., the last column.
      padding = multi_lvl_cls_scores.new_zeros(
          multi_lvl_cls_scores.shape[0], 1
      )
      multi_lvl_cls_scores = torch.cat(
          [multi_lvl_cls_scores, padding], dim=1
      )
  
      # Support exporting to onnx without nms
      if with_nms and cfg.get("nms", None) is not None:
          det_bboxes, det_labels = multiclass_nms(
              multi_lvl_bboxes,
              multi_lvl_cls_scores,
              cfg.score_thr,
              cfg.nms,
              cfg.max_per_img,
              score_factors=multi_lvl_conf_scores,
          )
          return det_bboxes, det_labels
      else:
          return (
              multi_lvl_bboxes,
              multi_lvl_cls_scores,
              multi_lvl_conf_scores,
          )
  
imports: import warnings
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import build_anchor_generator, build_assigner, build_bbox_coder, build_sampler, images_to_levels, multi_apply, multiclass_nms
  from ..builder import HEADS, build_loss
  from .base_dense_head import BaseDenseHead
  from .dense_test_mixins import BBoxTestMixin
label_desc: Use image node_id 8 for calling the YOLOV3Head obj's underlying member method code with example usage: obj._get_bboxes_single(pred_maps_list, scale_factor, cfg, rescale, with_nms) and returns: torch,  torch, det_bboxes,  det_labels, multi_lvl_bboxes,  multi_lvl_cls_scores,  multi_lvl_conf_scores