code: def predict_next_stage(
      model,
      plans,
      dataset,
      output_folder,
      stage_to_be_predicted_folder,
      mixed_precision,
      num_threads=4,
  ):
      output_folder = os.path.join(output_folder, "pred_next_stage")
      os.makedirs(output_folder, exist_ok=True)
  
      if "segmentation_export_params" in plans.keys():
          force_separate_z = plans["segmentation_export_params"][
              "force_separate_z"
          ]
          interpolation_order = plans["segmentation_export_params"][
              "interpolation_order"
          ]
          interpolation_order_z = plans["segmentation_export_params"][
              "interpolation_order_z"
          ]
      else:
          force_separate_z = None
          interpolation_order = 1
          interpolation_order_z = 0
  
      export_pool = Pool(num_threads)
      results = []
  
      model.eval()
      predictor = DynamicPredictor(model)
  
      for pat in dataset.dataset_val.keys():
          print(pat, "predict next stage...")
          data_file = dataset.dataset_val[pat]["data_file"]
          data_preprocessed = np.load(data_file)["data"][:-1]
          data_file_nofolder = data_file.split("/")[-1]
          data_file_nextstage = os.path.join(
              stage_to_be_predicted_folder, data_file_nofolder
          )
          data_nextstage = np.load(data_file_nextstage)["data"]
          target_shp = data_nextstage.shape[1:]
          output_file = os.path.join(
              output_folder,
              data_file_nextstage.split("/")[-1][:-4]
              + "_segFromPrevStage.npz",
          )
          if os.path.exists(output_file):
              print("{} already exists, skip.".format(output_file))
              continue
  
          (
              _,
              predicted_probabilities,
          ) = predict_preprocessed_data_return_seg_and_softmax(
              predictor,
              dataset,
              data_preprocessed,
              do_mirroring=dataset.data_aug_params["do_mirror"],
              mirror_axes=dataset.data_aug_params["mirror_axes"],
              mixed_precision=mixed_precision,
          )
  
          if np.prod(predicted_probabilities.shape) > (2e9 / 4 * 0.85):
              np.save(
                  output_file[:-4] + ".npy", predicted_probabilities
              )
              predicted_probabilities = output_file[:-4] + ".npy"
  
          results.append(
              export_pool.starmap_async(
                  resample_and_save,
                  [
                      (
                          predicted_probabilities,
                          target_shp,
                          output_file,
                          force_separate_z,
                          interpolation_order,
                          interpolation_order_z,
                      )
                  ],
              )
          )
  
      _ = [i.get() for i in results]
      export_pool.close()
      export_pool.join()
  
file_path: PaddleSeg/contrib/MedicalSeg/nnunet/utils/cascade_utils.py
imports: import os
  import numpy
  import paddle
  from typing import Tuple
  from multiprocessing import Pool
  from .None import resample_and_save, DynamicPredictor
label_desc: Use image node_id 2 for calling a global function with example usage: predict_next_stage(model, plans, dataset, output_folder, stage_to_be_predicted_folder, mixed_precision, num_threads) without return types