class_docstr: Mixin class for testing det bboxes via DenseHead.
class_docstr_tok: ["Mixin","class","for","testing","det","bboxes","via","DenseHead","."]
docstr: Test det bboxes with test time augmentation, can be applied in
  DenseHead except for ``RPNHead`` and its variants, e.g., ``GARPNHead``,
  etc.
  
  Args:
      feats (list[Tensor]): the outer list indicates test-time
          augmentations and inner Tensor should have a shape NxCxHxW,
          which contains features for all images in the batch.
      img_metas (list[list[dict]]): the outer list indicates test-time
          augs (multiscale, flip, etc.) and the inner list indicates
          images in a batch. each dict has image information.
      rescale (bool, optional): Whether to rescale the results.
          Defaults to False.
  
  Returns:
      list[tuple[Tensor, Tensor]]: Each item in result_list is 2-tuple.
          The first item is ``bboxes`` with shape (n, 5),
          where 5 represent (tl_x, tl_y, br_x, br_y, score).
          The shape of the second tensor in the tuple is ``labels``
          with shape (n,). The length of list should always be 1.
docstr_tok: ["Test","det","bboxes","with","test","time","augmentation",",","can","be","applied","in","DenseHead","except","for","``","RPNHead","``","and","its","variants",",","e.g.",",","``","GARPNHead","``",",","etc",".","Args",":","feats","(","list","[","Tensor","]",")",":","the","outer","list","indicates","test-time","augmentations","and","inner","Tensor","should","have","a","shape","NxCxHxW",",","which","contains","features","for","all","images","in","the","batch",".","img_metas","(","list","[","list","[","dict","]","]",")",":","the","outer","list","indicates","test-time","augs","(","multiscale",",","flip",",","etc",".",")","and","the","inner","list","indicates","images","in","a","batch",".","each","dict","has","image","information",".","rescale","(","bool",",","optional",")",":","Whether","to","rescale","the","results",".","Defaults","to","False",".","Returns",":","list","[","tuple","[","Tensor",",","Tensor","]","]",":","Each","item","in","result_list","is","2-tuple",".","The","first","item","is","``","bboxes","``","with","shape","(","n",",","5",")",",","where","5","represent","(","tl_x",",","tl_y",",","br_x",",","br_y",",","score",")",".","The","shape","of","the","second","tensor","in","the","tuple","is","``","labels","``","with","shape","(","n",",",")",".","The","length","of","list","should","always","be","1","."]
code: def aug_test_bboxes(self, feats, img_metas, rescale=False):
      """Test det bboxes with test time augmentation, can be applied in
      DenseHead except for ``RPNHead`` and its variants, e.g., ``GARPNHead``,
      etc.
  
      Args:
          feats (list[Tensor]): the outer list indicates test-time
              augmentations and inner Tensor should have a shape NxCxHxW,
              which contains features for all images in the batch.
          img_metas (list[list[dict]]): the outer list indicates test-time
              augs (multiscale, flip, etc.) and the inner list indicates
              images in a batch. each dict has image information.
          rescale (bool, optional): Whether to rescale the results.
              Defaults to False.
  
      Returns:
          list[tuple[Tensor, Tensor]]: Each item in result_list is 2-tuple.
              The first item is ``bboxes`` with shape (n, 5),
              where 5 represent (tl_x, tl_y, br_x, br_y, score).
              The shape of the second tensor in the tuple is ``labels``
              with shape (n,). The length of list should always be 1.
      """
  
      warnings.warn(
          "You are calling `aug_test_bboxes` in "
          "`dense_test_mixins`, but the `dense_test_mixins`"
          "will be deprecated soon. Please use "
          "`aug_test` instead."
      )
      # check with_nms argument
      gb_sig = signature(self.get_results)
      gb_args = [p.name for p in gb_sig.parameters.values()]
      gbs_sig = signature(self._get_results_single)
      gbs_args = [p.name for p in gbs_sig.parameters.values()]
      assert ("with_nms" in gb_args) and ("with_nms" in gbs_args), (
          f"{self.__class__.__name__}"
          " does not support test-time augmentation"
      )
  
      aug_bboxes = []
      aug_scores = []
      aug_labels = []
      for x, img_meta in zip(feats, img_metas):
          # only one image in the batch
          outs = self.forward(x)
          bbox_outputs = self.get_results(
              *outs,
              img_metas=img_meta,
              cfg=self.test_cfg,
              rescale=False,
              with_nms=False,
          )[0]
          aug_bboxes.append(bbox_outputs.bboxes)
          aug_scores.append(bbox_outputs.scores)
          if len(bbox_outputs) >= 3:
              aug_labels.append(bbox_outputs.labels)
  
      # after merging, bboxes will be rescaled to the original image size
      merged_bboxes, merged_scores = self.merge_aug_bboxes(
          aug_bboxes, aug_scores, img_metas
      )
      merged_labels = (
          torch.cat(aug_labels, dim=0) if aug_labels else None
      )
  
      if merged_bboxes.numel() == 0:
          det_bboxes = torch.cat(
              [merged_bboxes, merged_scores[:, None]], -1
          )
          return [
              (det_bboxes, merged_labels),
          ]
  
      det_bboxes, keep_idxs = batched_nms(
          merged_bboxes, merged_scores, merged_labels, self.test_cfg.nms
      )
      det_bboxes = det_bboxes[: self.test_cfg.max_per_img]
      det_labels = merged_labels[keep_idxs][: self.test_cfg.max_per_img]
  
      if rescale:
          _det_bboxes = det_bboxes
      else:
          _det_bboxes = det_bboxes.clone()
          _det_bboxes[:, :4] *= det_bboxes.new_tensor(
              img_metas[0][0]["scale_factor"]
          )
  
      results = InstanceData()
      results.bboxes = _det_bboxes[:, :4]
      results.scores = _det_bboxes[:, 4]
      results.labels = det_labels
      return [results]
  
file_path: mmdetection/mmdet/models/dense_heads/dense_test_mixins.py
imports: import sys
  import warnings
  from inspect import signature
  import torch
  from mmcv.ops import batched_nms
  from mmengine.structures import InstanceData
  from mmdet.structures.bbox import bbox_mapping_back
  from ..test_time_augs import merge_aug_proposals
label_desc: Use image node_id 2 for calling the BBoxTestMixin obj's underlying member method code with example usage: obj.aug_test_bboxes(feats, img_metas, rescale) and returns: list, list