code: def create_folds(self, progress_bar):
      data_generator = self.data_generator_params.create(
          PipelineMode.EVALUATION
      )
      if len(data_generator) == 0:
          raise ValueError("Empty dataset.")
      if len(data_generator) < self.n_folds:
          raise ValueError(
              "Less files than folds in the dataset which results in folds without any training example."
          )
  
      if not self.is_h5_dataset:
          if isinstance(self.data_generator_params, FileDataParams):
              # if a FileDataSet, we can just use the paths of the images
              self.folds = [[] for _ in range(self.n_folds)]
              file_data_gen: FileDataGenerator = data_generator
              for i, sample in enumerate(file_data_gen.samples()):
                  self.folds[i % self.n_folds].append(
                      sample["image_path"]
                  )
          else:
              raise NotImplementedError
      else:
          # else load the data of each fold and write it to hd5 data files
          with ExitStack() as stack:
              folds = [
                  stack.enter_context(
                      Hdf5DatasetWriter(
                          os.path.join(
                              self.output_dir, "fold{}".format(i)
                          )
                      )
                  )
                  for i in range(self.n_folds)
              ]
              for i, sample in tqdm_wrapper(
                  enumerate(data_generator.generate()),
                  progress_bar=progress_bar,
                  total=len(data_generator),
                  desc="Creating hdf5 files",
              ):
                  sample: Sample = sample
                  folds[i % self.n_folds].write(
                      sample.inputs, sample.targets
                  )
  
              self.folds = [f.files for f in folds]
  
file_path: calamari/calamari_ocr/ocr/training/cross_fold.py
imports: import os
  import json
  from contextlib import ExitStack
  from typing import List, Optional
  from tfaip.data.pipeline.definitions import Sample, PipelineMode
  from tfaip.util.multiprocessing.parallelmap import tqdm_wrapper
  from calamari_ocr.ocr.dataset.datareader.base import CalamariDataGeneratorParams
  from calamari_ocr.ocr.dataset.datareader.file import FileDataGenerator, FileDataParams
  from calamari_ocr.ocr.dataset.datareader.hdf5 import Hdf5DatasetWriter
label_desc: Use image node_id 4 for calling the CrossFold obj's underlying member method code with example usage: obj.create_folds(progress_bar) without return types