code: def box_results_with_nms_and_limit(scores, boxes):
      """Returns bounding-box detection results by thresholding on scores and
      applying non-maximum suppression (NMS).
  
      `boxes` has shape (#detections, 4 * #classes), where each row represents
      a list of predicted bounding boxes for each of the object classes in the
      dataset (including the background class). The detections in each row
      originate from the same object proposal.
  
      `scores` has shape (#detection, #classes), where each row represents a list
      of object detection confidence scores for each of the object classes in the
      dataset (including the background class). `scores[i, j]`` corresponds to the
      box at `boxes[i, j * 4:(j + 1) * 4]`.
      """
      num_classes = cfg.MODEL.NUM_CLASSES
      cls_boxes = [[] for _ in range(num_classes)]
      # Apply threshold on detection probabilities and apply NMS
      # Skip j = 0, because it's the background class
      for j in range(1, num_classes):
          inds = np.where(scores[:, j] > cfg.TEST.SCORE_THRESH)[0]
          scores_j = scores[inds, j]
          boxes_j = boxes[inds, j * 4 : (j + 1) * 4]
          dets_j = np.hstack((boxes_j, scores_j[:, np.newaxis])).astype(
              np.float32, copy=False
          )
          if cfg.TEST.SOFT_NMS.ENABLED:
              nms_dets, _ = box_utils.soft_nms(
                  dets_j,
                  sigma=cfg.TEST.SOFT_NMS.SIGMA,
                  overlap_thresh=cfg.TEST.NMS,
                  score_thresh=0.0001,
                  method=cfg.TEST.SOFT_NMS.METHOD,
              )
          else:
              keep = box_utils.nms(dets_j, cfg.TEST.NMS)
              nms_dets = dets_j[keep, :]
          # Refine the post-NMS boxes using bounding-box voting
          if cfg.TEST.BBOX_VOTE.ENABLED:
              nms_dets = box_utils.box_voting(
                  nms_dets,
                  dets_j,
                  cfg.TEST.BBOX_VOTE.VOTE_TH,
                  scoring_method=cfg.TEST.BBOX_VOTE.SCORING_METHOD,
              )
          cls_boxes[j] = nms_dets
  
      # Limit to max_per_image detections **over all classes**
      if cfg.TEST.DETECTIONS_PER_IM > 0:
          image_scores = np.hstack(
              [cls_boxes[j][:, -1] for j in range(1, num_classes)]
          )
          if len(image_scores) > cfg.TEST.DETECTIONS_PER_IM:
              image_thresh = np.sort(image_scores)[
                  -cfg.TEST.DETECTIONS_PER_IM
              ]
              for j in range(1, num_classes):
                  keep = np.where(cls_boxes[j][:, -1] >= image_thresh)[
                      0
                  ]
                  cls_boxes[j] = cls_boxes[j][keep, :]
  
      im_results = np.vstack(
          [cls_boxes[j] for j in range(1, num_classes)]
      )
      boxes = im_results[:, :-1]
      scores = im_results[:, -1]
      return scores, boxes, cls_boxes
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from collections import defaultdict
  import cv2
  import logging
  import numpy
  from caffe2.python import core
  from caffe2.python import workspace
  import pycocotools.mask
  from detectron.core.config import cfg
  from detectron.utils.timer import Timer
  import detectron.core.test_retinanet
  import detectron.modeling.FPN
  import detectron.utils.blob
  import detectron.utils.boxes
  import detectron.utils.image
  import detectron.utils.keypoints
label_desc: Use image node_id 19 for calling a global function with example usage: box_results_with_nms_and_limit(scores, boxes) and returns: scores,  boxes,  cls_boxes