code: def get_results(
      cf,
      img_shape,
      detections,
      detection_masks,
      box_results_list=None,
      return_masks=True,
  ):
      """
      Restores batch dimension of merged detections, unmolds detections, creates and fills results dict.
      :param img_shape:
      :param detections: (n_final_detections, (y1, x1, y2, x2, (z1), (z2), batch_ix, pred_class_id, pred_score)
      :param detection_masks: (n_final_detections, n_classes, y, x, (z)) raw molded masks as returned by mask-head.
      :param box_results_list: None or list of output boxes for monitoring/plotting.
      each element is a list of boxes per batch element.
      :param return_masks: boolean. If True, full resolution masks are returned for all proposals (speed trade-off).
      :return: results_dict: dictionary with keys:
               'boxes': list over batch elements. each batch element is a list of boxes. each box is a dictionary:
                        [[{box_0}, ... {box_n}], [{box_0}, ... {box_n}], ...]
               'seg_preds': pixel-wise class predictions (b, 1, y, x, (z)) with values [0, 1] only fg. vs. bg for now.
               class-specific return of masks will come with implementation of instance segmentation evaluation.
      """
      detections = detections.cpu().data.numpy()
      if cf.dim == 2:
          detection_masks = (
              detection_masks.permute(0, 2, 3, 1).cpu().data.numpy()
          )
      else:
          detection_masks = (
              detection_masks.permute(0, 2, 3, 4, 1).cpu().data.numpy()
          )
  
      # restore batch dimension of merged detections using the batch_ix info.
      batch_ixs = detections[:, cf.dim * 2]
      detections = [
          detections[batch_ixs == ix] for ix in range(img_shape[0])
      ]
      mrcnn_mask = [
          detection_masks[batch_ixs == ix] for ix in range(img_shape[0])
      ]
  
      # for test_forward, where no previous list exists.
      if box_results_list is None:
          box_results_list = [[] for _ in range(img_shape[0])]
  
      seg_preds = []
      # loop over batch and unmold detections.
      for ix in range(img_shape[0]):
          if 0 not in detections[ix].shape:
              boxes = detections[ix][:, : 2 * cf.dim].astype(np.int32)
              class_ids = detections[ix][:, 2 * cf.dim + 1].astype(
                  np.int32
              )
              scores = detections[ix][:, 2 * cf.dim + 2]
              masks = mrcnn_mask[ix][
                  np.arange(boxes.shape[0]), ..., class_ids
              ]
  
              # Filter out detections with zero area. Often only happens in early
              # stages of training when the network weights are still a bit random.
              if cf.dim == 2:
                  exclude_ix = np.where(
                      (boxes[:, 2] - boxes[:, 0])
                      * (boxes[:, 3] - boxes[:, 1])
                      <= 0
                  )[0]
              else:
                  exclude_ix = np.where(
                      (boxes[:, 2] - boxes[:, 0])
                      * (boxes[:, 3] - boxes[:, 1])
                      * (boxes[:, 5] - boxes[:, 4])
                      <= 0
                  )[0]
  
              if exclude_ix.shape[0] > 0:
                  boxes = np.delete(boxes, exclude_ix, axis=0)
                  class_ids = np.delete(class_ids, exclude_ix, axis=0)
                  scores = np.delete(scores, exclude_ix, axis=0)
                  masks = np.delete(masks, exclude_ix, axis=0)
  
              # Resize masks to original image size and set boundary threshold.
              full_masks = []
              permuted_image_shape = list(img_shape[2:]) + [
                  img_shape[1]
              ]
              if return_masks:
                  for i in range(masks.shape[0]):
                      # Convert neural network mask to full size mask.
                      full_masks.append(
                          mutils.unmold_mask_2D(
                              masks[i], boxes[i], permuted_image_shape
                          )
                          if cf.dim == 2
                          else mutils.unmold_mask_3D(
                              masks[i], boxes[i], permuted_image_shape
                          )
                      )
              # if masks are returned, take max over binary full masks of all predictions in this image.
              # right now only binary masks for plotting/monitoring. for instance segmentation return all proposal maks.
              final_masks = (
                  np.max(np.array(full_masks), 0)
                  if len(full_masks) > 0
                  else np.zeros((*permuted_image_shape[:-1],))
              )
  
              # add final perdictions to results.
              if 0 not in boxes.shape:
                  for ix2, score in enumerate(scores):
                      box_results_list[ix].append(
                          {
                              "box_coords": boxes[ix2],
                              "box_score": score,
                              "box_type": "det",
                              "box_pred_class_id": class_ids[ix2],
                          }
                      )
          else:
              # pad with zero dummy masks.
              final_masks = np.zeros(img_shape[2:])
  
          seg_preds.append(final_masks)
  
      # create and fill results dictionary.
      results_dict = {
          "boxes": box_results_list,
          "seg_preds": np.round(np.array(seg_preds))[
              :, np.newaxis
          ].astype("uint8"),
      }
  
      return results_dict
  
imports: import utils.model_utils
  import utils.exp_utils
  from cuda_functions.nms_2D.pth_nms import nms_gpu
  from cuda_functions.nms_3D.pth_nms import nms_gpu
  from cuda_functions.roi_align_2D.roi_align.crop_and_resize import CropAndResizeFunction
  from cuda_functions.roi_align_3D.roi_align.crop_and_resize import CropAndResizeFunction
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils
label_desc: Use image node_id 10 for calling a global function with example usage: get_results(cf, img_shape, detections, detection_masks, box_results_list, return_masks) and returns: results_dict