class_docstr: Fusion Head with Heuristic method.
class_docstr_tok: ["Fusion","Head","with","Heuristic","method","."]
docstr: Fuse the results of instance and semantic segmentations.
  
  Args:
      mask_results (:obj:`InstanceData`): Instance segmentation results,
          each contains ``bboxes``, ``labels``, ``scores`` and ``masks``.
      seg_preds (Tensor): The semantic segmentation results,
          (num_stuff + 1, H, W).
  
  Returns:
      Tensor: The panoptic segmentation result, (H, W).
docstr_tok: ["Fuse","the","results","of","instance","and","semantic","segmentations",".","Args",":","mask_results","(",":","obj",":","`","InstanceData","`",")",":","Instance","segmentation","results",",","each","contains","``","bboxes","``",",","``","labels","``",",","``","scores","``","and","``","masks","``",".","seg_preds","(","Tensor",")",":","The","semantic","segmentation","results",",","(","num_stuff","+","1",",","H",",","W",")",".","Returns",":","Tensor",":","The","panoptic","segmentation","result",",","(","H",",","W",")","."]
code: def _predict_single(
      self, mask_results: InstanceData, seg_preds: Tensor, **kwargs
  ) -> PixelData:
      """Fuse the results of instance and semantic segmentations.
  
      Args:
          mask_results (:obj:`InstanceData`): Instance segmentation results,
              each contains ``bboxes``, ``labels``, ``scores`` and ``masks``.
          seg_preds (Tensor): The semantic segmentation results,
              (num_stuff + 1, H, W).
  
      Returns:
          Tensor: The panoptic segmentation result, (H, W).
      """
      id_map, labels = self._lay_masks(
          mask_results, self.test_cfg.mask_overlap
      )
  
      seg_results = seg_preds.argmax(dim=0)
      seg_results = seg_results + self.num_things_classes
  
      pan_results = seg_results
      instance_id = 1
      for idx in range(len(mask_results)):
          _mask = id_map == (idx + 1)
          if _mask.sum() == 0:
              continue
          _cls = labels[idx]
          # simply trust detection
          segment_id = _cls + instance_id * INSTANCE_OFFSET
          pan_results[_mask] = segment_id
          instance_id += 1
  
      ids, counts = torch.unique(
          pan_results % INSTANCE_OFFSET, return_counts=True
      )
      stuff_ids = ids[ids >= self.num_things_classes]
      stuff_counts = counts[ids >= self.num_things_classes]
      ignore_stuff_ids = stuff_ids[
          stuff_counts < self.test_cfg.stuff_area_limit
      ]
  
      assert pan_results.ndim == 2
      pan_results[
          (
              pan_results.unsqueeze(2)
              == ignore_stuff_ids.reshape(1, 1, -1)
          ).any(dim=2)
      ] = self.num_classes
  
      pan_results = PixelData(sem_seg=pan_results[None].int())
      return pan_results
  
file_path: mmdetection/mmdet/models/seg_heads/panoptic_fusion_heads/heuristic_fusion_head.py
imports: from typing import List
  import torch
  from mmengine.structures import InstanceData, PixelData
  from torch import Tensor
  from mmdet.evaluation.functional import INSTANCE_OFFSET
  from mmdet.registry import MODELS
  from mmdet.utils import InstanceList, OptConfigType, OptMultiConfig, PixelList
  from .base_panoptic_fusion_head import BasePanopticFusionHead
label_desc: Use image node_id 4 for calling the HeuristicFusionHead obj's underlying member method code with example usage: obj._predict_single(mask_results, seg_preds) and returns: pan_results