class_docstr: Bbox head used in CrowdDet.
  
  .. code-block:: none
  
                                    /-> cls convs_1 -> cls fcs_1 -> cls_1
                                 |--
                                 |  \-> reg convs_1 -> reg fcs_1 -> reg_1
                                 |
                                 |  /-> cls convs_2 -> cls fcs_2 -> cls_2
      shared convs -> shared fcs |--
                                 |  \-> reg convs_2 -> reg fcs_2 -> reg_2
                                 |
                                 |                     ...
                                 |
                                 |  /-> cls convs_k -> cls fcs_k -> cls_k
                                 |--
                                    \-> reg convs_k -> reg fcs_k -> reg_k
  
  
  Args:
      num_instance (int): The number of branches after shared fcs.
          Defaults to 2.
      with_refine (bool): Whether to use refine module. Defaults to False.
      num_shared_convs (int): The number of shared convs. Defaults to 0.
      num_shared_fcs (int): The number of shared fcs. Defaults to 2.
      num_cls_convs (int): The number of cls convs. Defaults to 0.
      num_cls_fcs (int): The number of cls fcs. Defaults to 0.
      num_reg_convs (int): The number of reg convs. Defaults to 0.
      num_reg_fcs (int): The number of reg fcs. Defaults to 0.
      conv_out_channels (int): The number of conv out channels.
          Defaults to 256.
      fc_out_channels (int): The number of fc out channels. Defaults to 1024.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Defaults to None.
docstr: NMS for multi-instance prediction. Please refer to
  https://github.com/Purkialo/CrowdDet for more details.
  
  Args:
      bboxes (Tensor): predict bboxes.
      scores (Tensor): The score of each predict bbox.
      score_thr (float): bbox threshold, bboxes with scores lower than it
          will not be considered.
      iou_threshold (float): IoU threshold to be considered as
          conflicted.
      max_num (int, optional): if there are more than max_num bboxes
          after NMS, only top max_num will be kept. Default to -1.
  
  Returns:
      Tuple[Tensor, Tensor]: (bboxes, scores).
docstr_tok: ["NMS","for","multi-instance","prediction",".","Please","refer","to","https",":","\/\/github.com\/Purkialo\/CrowdDet","for","more","details",".","Args",":","bboxes","(","Tensor",")",":","predict","bboxes",".","scores","(","Tensor",")",":","The","score","of","each","predict","bbox",".","score_thr","(","float",")",":","bbox","threshold",",","bboxes","with","scores","lower","than","it","will","not","be","considered",".","iou_threshold","(","float",")",":","IoU","threshold","to","be","considered","as","conflicted",".","max_num","(","int",",","optional",")",":","if","there","are","more","than","max_num","bboxes","after","NMS",",","only","top","max_num","will","be","kept",".","Default","to","-1",".","Returns",":","Tuple","[","Tensor",",","Tensor","]",":","(","bboxes",",","scores",")","."]
code: def set_nms(
      bboxes: Tensor,
      scores: Tensor,
      score_thr: float,
      iou_threshold: float,
      max_num: int = -1,
  ) -> Tuple[Tensor, Tensor]:
      """NMS for multi-instance prediction. Please refer to
      https://github.com/Purkialo/CrowdDet for more details.
  
      Args:
          bboxes (Tensor): predict bboxes.
          scores (Tensor): The score of each predict bbox.
          score_thr (float): bbox threshold, bboxes with scores lower than it
              will not be considered.
          iou_threshold (float): IoU threshold to be considered as
              conflicted.
          max_num (int, optional): if there are more than max_num bboxes
              after NMS, only top max_num will be kept. Default to -1.
  
      Returns:
          Tuple[Tensor, Tensor]: (bboxes, scores).
      """
  
      bboxes = bboxes[scores > score_thr]
      scores = scores[scores > score_thr]
  
      ordered_scores, order = scores.sort(descending=True)
      ordered_bboxes = bboxes[order]
      roi_idx = ordered_bboxes[:, -1]
  
      keep = torch.ones(len(ordered_bboxes)) == 1
      ruler = torch.arange(len(ordered_bboxes))
  
      keep = keep.to(bboxes.device)
      ruler = ruler.to(bboxes.device)
  
      while ruler.shape[0] > 0:
          basement = ruler[0]
          ruler = ruler[1:]
          idx = roi_idx[basement]
          # calculate the body overlap
          basement_bbox = ordered_bboxes[:, :4][basement].reshape(-1, 4)
          ruler_bbox = ordered_bboxes[:, :4][ruler].reshape(-1, 4)
          overlap = bbox_overlaps(basement_bbox, ruler_bbox)
          indices = torch.where(overlap > iou_threshold)[1]
          loc = torch.where(roi_idx[ruler][indices] == idx)
          # the mask won't change in the step
          mask = keep[ruler[indices][loc]]
          keep[ruler[indices]] = False
          keep[ruler[indices][loc][mask]] = True
          ruler[~keep[ruler]] = -1
          ruler = ruler[ruler > 0]
  
      keep = keep[order.sort()[1]]
      return bboxes[keep][:max_num, :], scores[keep][:max_num]
  
imports: from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor, nn
  from mmdet.models.roi_heads.bbox_heads.bbox_head import BBoxHead
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.utils import empty_instances
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import bbox_overlaps
label_desc: Use image node_id 8 for calling the MultiInstanceBBoxHead obj's underlying member method code with example usage: obj.set_nms(bboxes, scores, score_thr, iou_threshold, max_num) and returns: bboxes,  scores