class_docstr: Box selector which selects the predicted boxes.
  The box selection is performed with the following steps:
  
  #. For each level, discard boxes with scores less than self.score_thresh.
  #. For each level, keep boxes with top self.topk_candidates_per_level scores.
  #. For the whole image, perform non-maximum suppression (NMS) on boxes, with overlapping threshold nms_thresh.
  #. For the whole image, keep boxes with top self.detections_per_img scores.
  
  Args:
      apply_sigmoid: whether to apply sigmoid to get scores from classification logits
      score_thresh: no box with scores less than score_thresh will be kept
      topk_candidates_per_level: max number of boxes to keep for each level
      nms_thresh: box overlapping threshold for NMS
      detections_per_img: max number of boxes to keep for each image
  
  Example:
  
      .. code-block:: python
  
          input_param = {
              "apply_sigmoid": True,
              "score_thresh": 0.1,
              "topk_candidates_per_level": 2,
              "nms_thresh": 0.1,
              "detections_per_img": 5,
          }
          box_selector = BoxSelector(**input_param)
          boxes = [torch.randn([3,6]), torch.randn([7,6])]
          logits = [torch.randn([3,3]), torch.randn([7,3])]
          spatial_size = (8,8,8)
          selected_boxes, selected_scores, selected_labels = box_selector.select_boxes_per_image(
              boxes, logits, spatial_size
          )
docstr: Select indices with highest scores.
  
  The indices selection is performed with the following steps:
  
  #. If self.apply_sigmoid, get scores by applying sigmoid to logits. Otherwise, use logits as scores.
  #. Discard indices with scores less than self.score_thresh
  #. Keep indices with top self.topk_candidates_per_level scores
  
  Args:
      logits: predicted classification logits, Tensor sized (N, num_classes)
  
  Return:
      - topk_idxs: selected M indices, Tensor sized (M, )
      - selected_scores: selected M scores, Tensor sized (M, )
      - selected_labels: selected M labels, Tensor sized (M, )
docstr_tok: ["Select","indices","with","highest","scores",".","The","indices","selection","is","performed","with","the","following","steps",":","#",".","If","self.apply_sigmoid",",","get","scores","by","applying","sigmoid","to","logits",".","Otherwise",",","use","logits","as","scores",".","#",".","Discard","indices","with","scores","less","than","self.score_thresh","#",".","Keep","indices","with","top","self.topk_candidates_per_level","scores","Args",":","logits",":","predicted","classification","logits",",","Tensor","sized","(","N",",","num_classes",")","Return",":","-","topk_idxs",":","selected","M","indices",",","Tensor","sized","(","M",",",")","-","selected_scores",":","selected","M","scores",",","Tensor","sized","(","M",",",")","-","selected_labels",":","selected","M","labels",",","Tensor","sized","(","M",",",")"]
code: def select_top_score_idx_per_level(
      self, logits: Tensor
  ) -> tuple[Tensor, Tensor, Tensor]:
      """
      Select indices with highest scores.
  
      The indices selection is performed with the following steps:
  
      #. If self.apply_sigmoid, get scores by applying sigmoid to logits. Otherwise, use logits as scores.
      #. Discard indices with scores less than self.score_thresh
      #. Keep indices with top self.topk_candidates_per_level scores
  
      Args:
          logits: predicted classification logits, Tensor sized (N, num_classes)
  
      Return:
          - topk_idxs: selected M indices, Tensor sized (M, )
          - selected_scores: selected M scores, Tensor sized (M, )
          - selected_labels: selected M labels, Tensor sized (M, )
      """
      num_classes = logits.shape[-1]
  
      # apply sigmoid to classification logits if asked
      if self.apply_sigmoid:
          scores = torch.sigmoid(logits.to(torch.float32)).flatten()
      else:
          scores = logits.flatten()
  
      # remove low scoring boxes
      keep_idxs = scores > self.score_thresh
      scores = scores[keep_idxs]
      flatten_topk_idxs = torch.where(keep_idxs)[0]
  
      # keep only topk scoring predictions
      num_topk = min(
          self.topk_candidates_per_level, flatten_topk_idxs.size(0)
      )
      selected_scores, idxs = scores.to(torch.float32).topk(
          num_topk
      )  # half precision not implemented for cpu float16
      flatten_topk_idxs = flatten_topk_idxs[idxs]
  
      selected_labels = flatten_topk_idxs % num_classes
  
      topk_idxs = floor_divide(flatten_topk_idxs, num_classes)
      return topk_idxs, selected_scores, selected_labels
  
file_path: MONAI/monai/apps/detection/utils/box_selector.py
imports: from __future__ import annotations
  from collections.abc import Callable
  import torch
  from torch import Tensor
  from monai.data.box_utils import batched_nms, box_iou, clip_boxes_to_image
  from monai.transforms.utils_pytorch_numpy_unification import floor_divide
label_desc: Use image node_id 2 for calling the BoxSelector obj's underlying member method code with example usage: obj.select_top_score_idx_per_level(logits) and returns: topk_idxs,  selected_scores,  selected_labels