docstr: Simple test for mask head without augmentation.
code: def simple_test_mask(
      self, x, img_metas, det_bboxes, det_labels, rescale=False
  ):
      """Simple test for mask head without augmentation."""
      # image shapes of images in the batch
      ori_shapes = tuple(meta["ori_shape"] for meta in img_metas)
      scale_factors = tuple(meta["scale_factor"] for meta in img_metas)
      num_imgs = len(det_bboxes)
      if all(det_bbox.shape[0] == 0 for det_bbox in det_bboxes):
          segm_results = [
              [[] for _ in range(self.mask_head.num_classes)]
              for _ in range(num_imgs)
          ]
      else:
          # if det_bboxes is rescaled to the original image size, we need to
          # rescale it back to the testing scale to obtain RoIs.
          if rescale and not isinstance(scale_factors[0], float):
              scale_factors = [
                  torch.from_numpy(scale_factor).to(
                      det_bboxes[0].device
                  )
                  for scale_factor in scale_factors
              ]
          if torch.onnx.is_in_onnx_export():
              # avoid mask_pred.split with static number of prediction
              mask_preds = []
              _bboxes = []
              for i, boxes in enumerate(det_bboxes):
                  boxes = boxes[:, :4]
                  if rescale:
                      boxes *= scale_factors[i]
                  _bboxes.append(boxes)
                  img_inds = boxes[:, :1].clone() * 0 + i
                  mask_rois = torch.cat([img_inds, boxes], dim=-1)
                  mask_result = self._mask_forward(x, mask_rois)
                  mask_preds.append(mask_result["mask_pred"])
          else:
              _bboxes = [
                  det_bboxes[i][:, :4] * scale_factors[i]
                  if rescale
                  else det_bboxes[i][:, :4]
                  for i in range(len(det_bboxes))
              ]
              mask_rois = bbox2roi(_bboxes)
              mask_results = self._mask_forward(x, mask_rois)
              mask_pred = mask_results["mask_pred"]
              # split batch mask prediction back to each image
              num_mask_roi_per_img = [
                  det_bbox.shape[0] for det_bbox in det_bboxes
              ]
              mask_preds = mask_pred.split(num_mask_roi_per_img, 0)
  
          # apply mask post-processing to each image individually
          segm_results = []
          for i in range(num_imgs):
              if det_bboxes[i].shape[0] == 0:
                  segm_results.append(
                      [[] for _ in range(self.mask_head.num_classes)]
                  )
              else:
                  segm_result = self.mask_head.get_seg_masks(
                      mask_preds[i],
                      _bboxes[i],
                      det_labels[i],
                      self.test_cfg,
                      ori_shapes[i],
                      scale_factors[i],
                      rescale,
                  )
                  segm_results.append(segm_result)
      return segm_results
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/test_mixins.py
imports: import logging
  import sys
  import torch
  from mmdet.core import bbox2roi, bbox_mapping, merge_aug_bboxes, merge_aug_masks, multiclass_nms
label_desc: Use image node_id 1 for calling the MaskTestMixin obj's underlying member method code with example usage: obj.simple_test_mask(x, img_metas, det_bboxes, det_labels, rescale) and returns: segm_results