code: def merge_2D_to_3D_preds_per_patient(inputs):
      """
      wrapper around 2Dto3D merging operation. Processes a single patient. Takes 2D patient results (slices in batch dimension)
      and returns 3D patient results (dummy batch dimension of 1). Applies an adaption of Non-Maximum Surpression
      (Detailed methodology is described in nms_2to3D).
      :return. results_dict_boxes: list over batch elements (1 in 3D). each element is a list over boxes, where each box is
                                   one dictionary: [[box_0, ...], [box_n,...]].
      :return. pid: string. patient id.
      """
      in_patient_results_list, pid, class_dict, merge_3D_iou = inputs
      out_patient_results_list = []
  
      for cl in list(class_dict.keys()):
          boxes, slice_ids = [], []
          # collect box predictions over batch dimension (slices) and store slice info as slice_ids.
          for bix, b in enumerate(in_patient_results_list):
              det_boxes = [
                  (ix, box)
                  for ix, box in enumerate(b)
                  if (
                      box["box_type"] == "det"
                      and box["box_pred_class_id"] == cl
                  )
              ]
              boxes += det_boxes
              slice_ids += [bix] * len(det_boxes)
  
          box_coords = np.array([b[1]["box_coords"] for b in boxes])
          box_scores = np.array([b[1]["box_score"] for b in boxes])
          slice_ids = np.array(slice_ids)
  
          if 0 not in box_scores.shape:
              keep_ix, keep_z = nms_2to3D(
                  np.concatenate(
                      (
                          box_coords,
                          box_scores[:, None],
                          slice_ids[:, None],
                      ),
                      axis=1,
                  ),
                  merge_3D_iou,
              )
          else:
              keep_ix, keep_z = [], []
  
          # store kept predictions in new results list and add corresponding z-dimension info to coordinates.
          for kix, kz in zip(keep_ix, keep_z):
              out_patient_results_list.append(
                  {
                      "box_type": "det",
                      "box_coords": list(box_coords[kix]) + kz,
                      "box_score": box_scores[kix],
                      "box_pred_class_id": cl,
                  }
              )
  
      out_patient_results_list += [
          box
          for b in in_patient_results_list
          for box in b
          if box["box_type"] == "gt"
      ]
      out_patient_results_list = [
          out_patient_results_list
      ]  # add dummy batch dimension 1 for 3D.
  
      return [out_patient_results_list, pid]
  
imports: import os
  import numpy
  import torch
  from scipy.stats import norm
  from collections import OrderedDict
  from multiprocessing import Pool
  import pickle
  import pandas
label_desc: Use image node_id 2 for calling a global function with example usage: merge_2D_to_3D_preds_per_patient(inputs) and returns: list