code: def merge_aug_proposals(aug_proposals, img_metas, cfg):
      """Merge augmented proposals (multiscale, flip, etc.)
  
      Args:
          aug_proposals (list[Tensor]): proposals from different testing
              schemes, shape (n, 5). Note that they are not rescaled to the
              original image size.
  
          img_metas (list[dict]): list of image info dict where each dict has:
              'img_shape', 'scale_factor', 'flip', and may also contain
              'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
              For details on the values of these keys see
              `mmdet/datasets/pipelines/formatting.py:Collect`.
  
          cfg (dict): rpn test config.
  
      Returns:
          Tensor: shape (n, 4), proposals corresponding to original image scale.
      """
  
      cfg = copy.deepcopy(cfg)
  
      # deprecate arguments warning
      if "nms" not in cfg or "max_num" in cfg or "nms_thr" in cfg:
          warnings.warn(
              "In rpn_proposal or test_cfg, "
              "nms_thr has been moved to a dict named nms as "
              "iou_threshold, max_num has been renamed as max_per_img, "
              "name of original arguments and the way to specify "
              "iou_threshold of NMS will be deprecated."
          )
      if "nms" not in cfg:
          cfg.nms = ConfigDict(
              dict(type="nms", iou_threshold=cfg.nms_thr)
          )
      if "max_num" in cfg:
          if "max_per_img" in cfg:
              assert cfg.max_num == cfg.max_per_img, (
                  f"You set max_num and "
                  f"max_per_img at the same time, but get {cfg.max_num} "
                  f"and {cfg.max_per_img} respectively"
                  f"Please delete max_num which will be deprecated."
              )
          else:
              cfg.max_per_img = cfg.max_num
      if "nms_thr" in cfg:
          assert cfg.nms.iou_threshold == cfg.nms_thr, (
              f"You set "
              f"iou_threshold in nms and "
              f"nms_thr at the same time, but get "
              f"{cfg.nms.iou_threshold} and {cfg.nms_thr}"
              f" respectively. Please delete the nms_thr "
              f"which will be deprecated."
          )
  
      recovered_proposals = []
      for proposals, img_info in zip(aug_proposals, img_metas):
          img_shape = img_info["img_shape"]
          scale_factor = img_info["scale_factor"]
          flip = img_info["flip"]
          flip_direction = img_info["flip_direction"]
          _proposals = proposals.clone()
          _proposals[:, :4] = bbox_mapping_back(
              _proposals[:, :4],
              img_shape,
              scale_factor,
              flip,
              flip_direction,
          )
          recovered_proposals.append(_proposals)
      aug_proposals = torch.cat(recovered_proposals, dim=0)
      merged_proposals, _ = nms(
          aug_proposals[:, :4].contiguous(),
          aug_proposals[:, -1].contiguous(),
          cfg.nms.iou_threshold,
      )
      scores = merged_proposals[:, 4]
      _, order = scores.sort(0, descending=True)
      num = min(cfg.max_per_img, merged_proposals.shape[0])
      order = order[:num]
      merged_proposals = merged_proposals[order, :]
      return merged_proposals
  
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 1 for calling a global function with example usage: merge_aug_proposals(aug_proposals, img_metas, cfg) and returns: merged_proposals