code: def verify_training_dataset(
      folder,
      num_modalities,
      identifiers,
      expected_labels,
      train_images_dir="imagesTr",
      train_labels_dir="labelsTr",
      default_num_threads=8,
  ):
      imagesTr_folder = join_paths(folder, train_images_dir)
      nii_files_in_imagesTr = [
          nii_path
          for nii_path in os.listdir(imagesTr_folder)
          if os.path.isfile(join_paths(imagesTr_folder, nii_path))
          and nii_path.endswith(".nii.gz")
      ]
      labelsTr_folder = join_paths(folder, train_labels_dir)
      nii_files_in_labelsTr = [
          nii_path
          for nii_path in os.listdir(labelsTr_folder)
          if os.path.isfile(join_paths(labelsTr_folder, nii_path))
          and nii_path.endswith(".nii.gz")
      ]
  
      label_files = []
      for c in identifiers:
          # check if all files are present
          expected_label_file = join_paths(
              folder, train_labels_dir, c + ".nii.gz"
          )
          label_files.append(expected_label_file)
          expected_image_files = [
              join_paths(
                  folder, train_images_dir, c + "_%04.0d.nii.gz" % i
              )
              for i in range(num_modalities)
          ]
          assert os.path.isfile(
              expected_label_file
          ), "Could not find label file for case {}. Expected file: {}".format(
              c, expected_label_file
          )
          assert all(
              [os.path.isfile(i) for i in expected_image_files]
          ), "Some image files are missing for case {}. Expected files: {}.".format(
              c, expected_image_files
          )
          # check that all modalities and the label have the same shape and geometry
          verify_same_geometry_and_shape_and_nonan(
              expected_image_files, expected_label_file
          )
  
          for i in expected_image_files:
              nii_files_in_imagesTr.remove(os.path.basename(i))
          nii_files_in_labelsTr.remove(
              os.path.basename(expected_label_file)
          )
  
      assert (
          len(nii_files_in_imagesTr) == 0
      ), "There are training cases in {} that are not listed in dataset json file.".format(
          train_images_dir
      )
      assert (
          len(nii_files_in_labelsTr) == 0
      ), "There are training cases in {} that are not listed in dataset json file.".format(
          train_labels_dir
      )
  
      # check if labels are in consecutive order
      assert (
          expected_labels[0] == 0
      ), "The first label must be 0 and maps to the background"
      labels_valid_consecutive = np.ediff1d(expected_labels) == 1
      assert all(
          labels_valid_consecutive
      ), f"Labels must be in consecutive order (0, 1, 2, ...). The labels {np.array(expected_labels)[1:][~labels_valid_consecutive]} do not satisfy this restriction"
  
      p = Pool(default_num_threads)
      results = p.starmap(
          verify_contains_only_expected_labels,
          zip(label_files, [expected_labels] * len(label_files)),
      )
      p.close()
      p.join()
  
      for i, r in enumerate(results):
          assert r[
              0
          ], "Unexpected labels found in file {}. Found these unexpected values {}.".format(
              label_files[i], r[1]
          )
  
file_path: PaddleSeg/contrib/MedicalSeg/tools/preprocess_utils/integrity_checks.py
imports: import os
  import json
  import numpy
  import SimpleITK
  import nibabel
  from multiprocessing import Pool
  from .load_image import load_series
  from .path_utils import join_paths
label_desc: Use image node_id 5 for calling a global function with example usage: verify_training_dataset(folder, num_modalities, identifiers, expected_labels, train_images_dir, train_labels_dir, default_num_threads) without return types