class_docstr: Merge augmented detection results, only bboxes corresponding score under
  flipping and multi-scale resizing can be processed now.
  
  Examples:
      >>> tta_model = dict(
      >>>     type='DetTTAModel',
      >>>     tta_cfg=dict(nms=dict(
      >>>                     type='nms',
      >>>                     iou_threshold=0.5),
      >>>                     max_per_img=100))
      >>>
      >>> tta_pipeline = [
      >>>     dict(type='LoadImageFromFile',
      >>>          backend_args=None),
      >>>     dict(
      >>>         type='TestTimeAug',
      >>>         transforms=[[
      >>>             dict(type='Resize',
      >>>                  scale=(1333, 800),
      >>>                  keep_ratio=True),
      >>>         ], [
      >>>             dict(type='RandomFlip', prob=1.),
      >>>             dict(type='RandomFlip', prob=0.)
      >>>         ], [
      >>>             dict(
      >>>                 type='PackDetInputs',
      >>>                 meta_keys=('img_id', 'img_path', 'ori_shape',
      >>>                         'img_shape', 'scale_factor', 'flip',
      >>>                         'flip_direction'))
      >>>         ]])]
class_docstr_tok: ["Merge","augmented","detection","results",",","only","bboxes","corresponding","score","under","flipping","and","multi-scale","resizing","can","be","processed","now",".","Examples",":",">",">",">","tta_model","=","dict","(",">",">",">","type='DetTTAModel","'",",",">",">",">","tta_cfg=dict","(","nms=dict","(",">",">",">","type='nms","'",",",">",">",">","iou_threshold=0.5",")",",",">",">",">","max_per_img=100",")",")",">",">",">",">",">",">","tta_pipeline","=","[",">",">",">","dict","(","type='LoadImageFromFile","'",",",">",">",">","backend_args=None",")",",",">",">",">","dict","(",">",">",">","type='TestTimeAug","'",",",">",">",">","transforms=","[","[",">",">",">","dict","(","type='Resize","'",",",">",">",">","scale=","(","1333",",","800",")",",",">",">",">","keep_ratio=True",")",",",">",">",">","]",",","[",">",">",">","dict","(","type='RandomFlip","'",",","prob=1",".",")",",",">",">",">","dict","(","type='RandomFlip","'",",","prob=0",".",")",">",">",">","]",",","[",">",">",">","dict","(",">",">",">","type='PackDetInputs","'",",",">",">",">","meta_keys=","(","'img_id","'",",","'img_path","'",",","'ori_shape","'",",",">",">",">","'img_shape","'",",","'scale_factor","'",",","'flip","'",",",">",">",">","'flip_direction","'",")",")",">",">",">","]","]",")","]"]
docstr: Merge predictions which come form the different views of one image
  to one prediction.
  
  Args:
      data_samples (List[DetDataSample]): List of predictions
      of enhanced data which come form one image.
  Returns:
      List[DetDataSample]: Merged prediction.
docstr_tok: ["Merge","predictions","which","come","form","the","different","views","of","one","image","to","one","prediction",".","Args",":","data_samples","(","List","[","DetDataSample","]",")",":","List","of","predictions","of","enhanced","data","which","come","form","one","image",".","Returns",":","List","[","DetDataSample","]",":","Merged","prediction","."]
code: def _merge_single_sample(
      self, data_samples: List[DetDataSample]
  ) -> DetDataSample:
      """Merge predictions which come form the different views of one image
      to one prediction.
  
      Args:
          data_samples (List[DetDataSample]): List of predictions
          of enhanced data which come form one image.
      Returns:
          List[DetDataSample]: Merged prediction.
      """
      aug_bboxes = []
      aug_scores = []
      aug_labels = []
      img_metas = []
      # TODO: support instance segmentation TTA
      assert (
          data_samples[0].pred_instances.get("masks", None) is None
      ), "TTA of instance segmentation does not support now."
      for data_sample in data_samples:
          aug_bboxes.append(data_sample.pred_instances.bboxes)
          aug_scores.append(data_sample.pred_instances.scores)
          aug_labels.append(data_sample.pred_instances.labels)
          img_metas.append(data_sample.metainfo)
  
      merged_bboxes, merged_scores = self.merge_aug_bboxes(
          aug_bboxes, aug_scores, img_metas
      )
      merged_labels = torch.cat(aug_labels, dim=0)
  
      if merged_bboxes.numel() == 0:
          return data_samples[0]
  
      det_bboxes, keep_idxs = batched_nms(
          merged_bboxes, merged_scores, merged_labels, self.tta_cfg.nms
      )
  
      det_bboxes = det_bboxes[: self.tta_cfg.max_per_img]
      det_labels = merged_labels[keep_idxs][: self.tta_cfg.max_per_img]
  
      results = InstanceData()
      _det_bboxes = det_bboxes.clone()
      results.bboxes = _det_bboxes[:, :-1]
      results.scores = _det_bboxes[:, -1]
      results.labels = det_labels
      det_results = data_samples[0]
      det_results.pred_instances = results
      return det_results
  
file_path: mmdetection/mmdet/models/test_time_augs/det_tta.py
imports: from typing import List, Tuple
  import torch
  from mmcv.ops import batched_nms
  from mmengine.model import BaseTTAModel
  from mmengine.registry import MODELS
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.structures import DetDataSample
  from mmdet.structures.bbox import bbox_flip
label_desc: Use image node_id 4 for calling the DetTTAModel obj's underlying member method code with example usage: obj._merge_single_sample(data_samples) and returns: det_results, data_samples