docstr: Transform a batch of output features extracted from the head into
  mask results.
  
  Args:
      mask_preds (tuple[Tensor]): Tuple of predicted foreground masks,
          each has shape (n, num_classes, h, w).
      results_list (list[:obj:`InstanceData`]): Detection results of
          each image.
      batch_img_metas (list[dict]): List of image information.
      rcnn_test_cfg (obj:`ConfigDict`): `test_cfg` of Bbox Head.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
      activate_map (book): Whether get results with augmentations test.
          If True, the `mask_preds` will not process with sigmoid.
          Defaults to False.
  
  Returns:
      list[:obj:`InstanceData`]: Detection results of each image
      after the post process. Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
          - masks (Tensor): Has a shape (num_instances, H, W).
docstr_tok: ["Transform","a","batch","of","output","features","extracted","from","the","head","into","mask","results",".","Args",":","mask_preds","(","tuple","[","Tensor","]",")",":","Tuple","of","predicted","foreground","masks",",","each","has","shape","(","n",",","num_classes",",","h",",","w",")",".","results_list","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Detection","results","of","each","image",".","batch_img_metas","(","list","[","dict","]",")",":","List","of","image","information",".","rcnn_test_cfg","(","obj",":","`","ConfigDict","`",")",":","`","test_cfg","`","of","Bbox","Head",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","activate_map","(","book",")",":","Whether","get","results","with","augmentations","test",".","If","True",",","the","`","mask_preds","`","will","not","process","with","sigmoid",".","Defaults","to","False",".","Returns",":","list","[",":","obj",":","`","InstanceData","`","]",":","Detection","results","of","each","image","after","the","post","process",".","Each","item","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")",".","-","masks","(","Tensor",")",":","Has","a","shape","(","num_instances",",","H",",","W",")","."]
code: def predict_by_feat(
      self,
      mask_preds: Tuple[Tensor],
      results_list: List[InstanceData],
      batch_img_metas: List[dict],
      rcnn_test_cfg: ConfigDict,
      rescale: bool = False,
      activate_map: bool = False,
  ) -> InstanceList:
      """Transform a batch of output features extracted from the head into
      mask results.
  
      Args:
          mask_preds (tuple[Tensor]): Tuple of predicted foreground masks,
              each has shape (n, num_classes, h, w).
          results_list (list[:obj:`InstanceData`]): Detection results of
              each image.
          batch_img_metas (list[dict]): List of image information.
          rcnn_test_cfg (obj:`ConfigDict`): `test_cfg` of Bbox Head.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
          activate_map (book): Whether get results with augmentations test.
              If True, the `mask_preds` will not process with sigmoid.
              Defaults to False.
  
      Returns:
          list[:obj:`InstanceData`]: Detection results of each image
          after the post process. Each item usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
              - masks (Tensor): Has a shape (num_instances, H, W).
      """
      assert (
          len(mask_preds) == len(results_list) == len(batch_img_metas)
      )
  
      for img_id in range(len(batch_img_metas)):
          img_meta = batch_img_metas[img_id]
          results = results_list[img_id]
          bboxes = results.bboxes
          if bboxes.shape[0] == 0:
              results_list[img_id] = empty_instances(
                  [img_meta],
                  bboxes.device,
                  task_type="mask",
                  instance_results=[results],
                  mask_thr_binary=rcnn_test_cfg.mask_thr_binary,
              )[0]
          else:
              im_mask = self._predict_by_feat_single(
                  mask_preds=mask_preds[img_id],
                  bboxes=bboxes,
                  labels=results.labels,
                  img_meta=img_meta,
                  rcnn_test_cfg=rcnn_test_cfg,
                  rescale=rescale,
                  activate_map=activate_map,
              )
              results.masks = im_mask
      return results_list
  
imports: from typing import List, Tuple
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, build_conv_layer, build_upsample_layer
  from mmcv.ops.carafe import CARAFEPack
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule, ModuleList
  from mmengine.structures import InstanceData
  from torch import Tensor
  from torch.nn.modules.utils import _pair
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.utils import empty_instances
  from mmdet.registry import MODELS
  from mmdet.structures.mask import mask_target
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptMultiConfig
label_desc: Use image node_id 6 for calling the FCNMaskHead obj's underlying member method code with example usage: obj.predict_by_feat(mask_preds, results_list, batch_img_metas, rcnn_test_cfg, rescale, activate_map) and returns: results_list