code: def create_dataset_generator(data_path, batch_size, read_encoded):
      ds = ShuffledFilesDataSet(data_path)
      epoch_i = -1
  
      def create_epoch():
          nonlocal epoch_i
          epoch_i += 1
          i = 0
          try:
              while True:
                  batch_imgs, batch_labels = [], []
                  for _ in range(batch_size):
                      jpeg_filename, label = ds.get_sample(i, epoch_i)
                      if read_encoded:
                          jpeg = np.fromfile(
                              jpeg_filename, dtype=np.uint8
                          )
                      else:
                          jpeg = cv2.imread(jpeg_filename)
                      batch_imgs.append(jpeg)
                      batch_labels.append(np.int32([label]))
                      i += 1
                  yield batch_imgs, batch_labels
          except StopIteration:
              pass
  
      return create_epoch, len(ds)
  
imports: import argparse
  import cv2
  import numpy
  import nvidia.dali
  import nvidia.dali.types
  import os
label_desc: Use image node_id 1 for calling a global function with example usage: create_dataset_generator(data_path, batch_size, read_encoded) and returns: create_epoch,  len