class_docstr: Fusion Head with Heuristic method.
class_docstr_tok: ["Fusion","Head","with","Heuristic","method","."]
docstr: Lay instance masks to a result map.
  
  Args:
      mask_results (:obj:`InstanceData`): Instance segmentation results,
          each contains ``bboxes``, ``labels``, ``scores`` and ``masks``.
      overlap_thr (float): Threshold to determine whether two masks
          overlap. default: 0.5.
  
  Returns:
      Tensor: The result map, (H, W).
docstr_tok: ["Lay","instance","masks","to","a","result","map",".","Args",":","mask_results","(",":","obj",":","`","InstanceData","`",")",":","Instance","segmentation","results",",","each","contains","``","bboxes","``",",","``","labels","``",",","``","scores","``","and","``","masks","``",".","overlap_thr","(","float",")",":","Threshold","to","determine","whether","two","masks","overlap",".","default",":","0.5",".","Returns",":","Tensor",":","The","result","map",",","(","H",",","W",")","."]
code: def _lay_masks(
      self, mask_results: InstanceData, overlap_thr: float = 0.5
  ) -> Tensor:
      """Lay instance masks to a result map.
  
      Args:
          mask_results (:obj:`InstanceData`): Instance segmentation results,
              each contains ``bboxes``, ``labels``, ``scores`` and ``masks``.
          overlap_thr (float): Threshold to determine whether two masks
              overlap. default: 0.5.
  
      Returns:
          Tensor: The result map, (H, W).
      """
      bboxes = mask_results.bboxes
      scores = mask_results.scores
      labels = mask_results.labels
      masks = mask_results.masks
  
      num_insts = bboxes.shape[0]
      id_map = torch.zeros(
          masks.shape[-2:], device=bboxes.device, dtype=torch.long
      )
      if num_insts == 0:
          return id_map, labels
  
      # Sort by score to use heuristic fusion
      order = torch.argsort(-scores)
      bboxes = bboxes[order]
      labels = labels[order]
      segm_masks = masks[order]
  
      instance_id = 1
      left_labels = []
      for idx in range(bboxes.shape[0]):
          _cls = labels[idx]
          _mask = segm_masks[idx]
          instance_id_map = (
              torch.ones_like(_mask, dtype=torch.long) * instance_id
          )
          area = _mask.sum()
          if area == 0:
              continue
  
          pasted = id_map > 0
          intersect = (_mask * pasted).sum()
          if (intersect / (area + 1e-5)) > overlap_thr:
              continue
  
          _part = _mask * (~pasted)
          id_map = torch.where(_part, instance_id_map, id_map)
          left_labels.append(_cls)
          instance_id += 1
  
      if len(left_labels) > 0:
          instance_labels = torch.stack(left_labels)
      else:
          instance_labels = bboxes.new_zeros((0,), dtype=torch.long)
      assert instance_id == (len(instance_labels) + 1)
      return id_map, instance_labels
  
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 3 for calling the HeuristicFusionHead obj's underlying member method code with example usage: obj._lay_masks(mask_results, overlap_thr) and returns: id_map,  instance_labels, id_map,  labels