code: def index_subdirectory(
      directory, class_indices, follow_links, formats
  ):
      """Recursively walks directory and list image paths and their class index.
  
      Args:
          directory: string, target directory.
          class_indices: dict mapping class names to their index.
          follow_links: boolean, whether to recursively follow subdirectories
              (if False, we only list top-level images in `directory`).
          formats: Allowlist of file extensions to index (e.g. ".jpg", ".txt").
  
      Returns:
          tuple `(filenames, labels)`. `filenames` is a list of relative file
              paths, and `labels` is a list of integer labels corresponding
              to these files.
      """
      dirname = os.path.basename(directory)
      valid_files = iter_valid_files(directory, follow_links, formats)
      labels = []
      filenames = []
      for root, fname in valid_files:
          labels.append(class_indices[dirname])
          absolute_path = tf.io.gfile.join(root, fname)
          relative_path = tf.io.gfile.join(
              dirname, os.path.relpath(absolute_path, directory)
          )
          filenames.append(relative_path)
      return filenames, labels
  
imports: import os
  import random
  import time
  import warnings
  from multiprocessing.pool import ThreadPool
  import numpy
  from keras.api_export import keras_export
  from keras.utils import io_utils
  from keras.utils.module_utils import tensorflow
label_desc: Use image node_id 14 for calling a global function with example usage: index_subdirectory(directory, class_indices, follow_links, formats) and returns: filenames,  labels