code: def merge_aug_results(aug_batch_results, aug_batch_img_metas):
      """Merge augmented detection results, only bboxes corresponding score under
      flipping and multi-scale resizing can be processed now.
  
      Args:
          aug_batch_results (list[list[[obj:`InstanceData`]]):
              Detection results of multiple images with
              different augmentations.
              The outer list indicate the augmentation . The inter
              list indicate the batch dimension.
              Each item usually contains the following keys.
  
              - scores (Tensor): Classification scores, in shape
                (num_instance,)
              - labels (Tensor): Labels of bboxes, in shape
                (num_instances,).
              - bboxes (Tensor): In shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
          aug_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 in the list contains
              information of an image in the batch.
  
      Returns:
          batch_results (list[obj:`InstanceData`]): Same with
          the input `aug_results` except that all bboxes have
          been mapped to the original scale.
      """
      num_augs = len(aug_batch_results)
      num_imgs = len(aug_batch_results[0])
  
      batch_results = []
      aug_batch_results = copy.deepcopy(aug_batch_results)
      for img_id in range(num_imgs):
          aug_results = []
          for aug_id in range(num_augs):
              img_metas = aug_batch_img_metas[aug_id][img_id]
              results = aug_batch_results[aug_id][img_id]
  
              img_shape = img_metas["img_shape"]
              scale_factor = img_metas["scale_factor"]
              flip = img_metas["flip"]
              flip_direction = img_metas["flip_direction"]
              bboxes = bbox_mapping_back(
                  results.bboxes,
                  img_shape,
                  scale_factor,
                  flip,
                  flip_direction,
              )
              results.bboxes = bboxes
              aug_results.append(results)
          merged_aug_results = results.cat(aug_results)
          batch_results.append(merged_aug_results)
  
      return batch_results
  
file_path: mmdetection/mmdet/models/test_time_augs/merge_augs.py
imports: import copy
  import warnings
  from typing import List, Optional, Union
  import numpy
  import torch
  from mmcv.ops import nms
  from mmengine.config import ConfigDict
  from torch import Tensor
  from mmdet.structures.bbox import bbox_mapping_back
label_desc: Use image node_id 3 for calling a global function with example usage: merge_aug_results(aug_batch_results, aug_batch_img_metas) and returns: batch_results