code: def create_csv_output(results_list, cf, logger):
      """
      Write out test set predictions to .csv file. output format is one line per prediction:
      PatientID | PredictionID | [y1 x1 y2 x2 (z1) (z2)] | score | pred_classID
      Note, that prediction coordinates correspond to images as loaded for training/testing and need to be adapted when
      plotted over raw data (before preprocessing/resampling).
      :param results_list: [[patient_results, patient_id], [patient_results, patient_id], ...]
      """
  
      logger.info(
          "creating csv output file at {}".format(
              os.path.join(cf.exp_dir, "results.csv")
          )
      )
      predictions_df = pd.DataFrame(
          columns=[
              "patientID",
              "predictionID",
              "coords",
              "score",
              "pred_classID",
          ]
      )
      for r in results_list:
          pid = r[1]
  
          # optionally load resampling info from preprocessing to match output predictions with raw data.
          # with open(os.path.join(cf.exp_dir, 'test_resampling_info', pid), 'rb') as handle:
          #    resampling_info = pickle.load(handle)
  
          for bix, box in enumerate(r[0][0]):
              assert box["box_type"] == "det", box["box_type"]
              coords = box["box_coords"]
              score = box["box_score"]
              pred_class_id = box["box_pred_class_id"]
              out_coords = []
              if score >= cf.min_det_thresh:
                  out_coords.append(
                      coords[0]
                  )  # * resampling_info['scale'][0])
                  out_coords.append(
                      coords[1]
                  )  # * resampling_info['scale'][1])
                  out_coords.append(
                      coords[2]
                  )  # * resampling_info['scale'][0])
                  out_coords.append(
                      coords[3]
                  )  # * resampling_info['scale'][1])
                  if len(coords) > 4:
                      out_coords.append(
                          coords[4]
                      )  # * resampling_info['scale'][2] + resampling_info['z_crop'])
                      out_coords.append(
                          coords[5]
                      )  # * resampling_info['scale'][2] + resampling_info['z_crop'])
  
                  predictions_df.loc[len(predictions_df)] = [
                      pid,
                      bix,
                      out_coords,
                      score,
                      pred_class_id,
                  ]
      try:
          fold = cf.fold
      except:
          fold = "hold_out"
      predictions_df.to_csv(
          os.path.join(cf.exp_dir, "results_{}.csv".format(fold)),
          index=False,
      )
  
imports: import numpy
  import logging
  import subprocess
  import os
  import torch
  from collections import OrderedDict
  import plotting
  import sys
  import importlib.util
  import pandas
  import pickle
label_desc: Use image node_id 6 for calling a global function with example usage: create_csv_output(results_list, cf, logger) without return types