code: def consolidate_folds(
      output_folder_base,
      validation_folder_name: str = "validation_raw",
      advanced_postprocessing: bool = False,
      folds: Tuple[int] = (0, 1, 2, 3, 4),
      num_threads=4,
  ):
      output_folder_raw = os.path.join(
          output_folder_base, "cv_niftis_raw"
      )
      if os.path.isdir(output_folder_raw):
          shutil.rmtree(output_folder_raw)
  
      output_folder_gt = os.path.join(output_folder_base, "gt_niftis")
      collect_cv_niftis(
          output_folder_base,
          output_folder_raw,
          validation_folder_name,
          folds,
      )
  
      num_niftis_gt = len(
          subfiles(
              os.path.join(output_folder_base, "gt_niftis"),
              suffix=".nii.gz",
          )
      )
      num_niftis = len(subfiles(output_folder_raw, suffix=".nii.gz"))
      if num_niftis != num_niftis_gt:
          raise AssertionError(
              "If does not seem like you trained all the folds! Train all folds first!"
          )
  
      with open(
          os.path.join(
              output_folder_base,
              "fold_0",
              validation_folder_name,
              "summary.json",
          ),
          "r",
      ) as f:
          json_data = json.load(f)
      summary_info = json_data["results"]["mean"]
  
      classes = [int(i) for i in summary_info.keys()]
      niftis = [
          file
          for file in os.listdir(output_folder_raw)
          if os.path.isfile(os.path.join(output_folder_raw, file))
          and file.endswith(".nii.gz")
      ]
      test_pred_pairs = [
          (
              os.path.join(output_folder_raw, i),
              os.path.join(output_folder_gt, i),
          )
          for i in niftis
      ]
  
      _ = aggregate_scores(
          test_pred_pairs,
          labels=classes,
          json_output_file=os.path.join(
              output_folder_raw, "summary.json"
          ),
          num_threads=num_threads,
      )
  
      determine_postprocessing(
          output_folder_base,
          output_folder_gt,
          "cv_niftis_raw",
          final_subf_name="cv_niftis_postprocessed",
          processes=num_threads,
          advanced_postprocessing=advanced_postprocessing,
      )
  
file_path: PaddleSeg/contrib/MedicalSeg/nnunet/all_folds_eval.py
imports: import argparse
  import os
  import sys
  import json
  import shutil
  from typing import Tuple
  from nnunet.utils import aggregate_scores, determine_postprocessing
label_desc: Use image node_id 2 for calling a global function with example usage: consolidate_folds(output_folder_base, validation_folder_name, advanced_postprocessing, folds, num_threads) without return types