code: def merge_aug_masks(
      aug_masks, img_metas, rcnn_test_cfg, weights=None
  ):
      """Merge augmented mask prediction.
  
      Args:
          aug_masks (list[ndarray]): shape (n, #class, h, w)
          img_shapes (list[ndarray]): shape (3, ).
          rcnn_test_cfg (dict): rcnn test config.
  
      Returns:
          tuple: (bboxes, scores)
      """
      recovered_masks = []
      for mask, img_info in zip(aug_masks, img_metas):
          flip = img_info[0]["flip"]
          flip_direction = img_info[0]["flip_direction"]
          if flip:
              if flip_direction == "horizontal":
                  mask = mask[:, :, :, ::-1]
              elif flip_direction == "vertical":
                  mask = mask[:, :, ::-1, :]
              else:
                  raise ValueError(
                      f"Invalid flipping direction '{flip_direction}'"
                  )
          recovered_masks.append(mask)
  
      if weights is None:
          merged_masks = np.mean(recovered_masks, axis=0)
      else:
          merged_masks = np.average(
              np.array(recovered_masks),
              axis=0,
              weights=np.array(weights),
          )
      return merged_masks
  
file_path: insightface/detection/scrfd/mmdet/core/post_processing/merge_augs.py
imports: import numpy
  import torch
  from mmcv.ops import nms
  from ..bbox import bbox_mapping_back
label_desc: Use image node_id 4 for calling a global function with example usage: merge_aug_masks(aug_masks, img_metas, rcnn_test_cfg, weights) and returns: merged_masks