code: def index_subdirectory(
      directory, class_indices, follow_links, formats
  ):
      """Recursively walks directory and list image paths and their class index.
  
      # Arguments
        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 = os.path.join(root, fname)
          relative_path = os.path.join(
              dirname, os.path.relpath(absolute_path, directory)
          )
          filenames.append(relative_path)
      return filenames, labels
  
file_path: autokeras/autokeras/utils/io_utils.py
imports: import json
  import multiprocessing
  import os
  from typing import Optional
  from typing import Tuple
  import numpy
  import tensorflow
  from keras_tuner.engine import hyperparameters
label_desc: Use image node_id 5 for calling a global function with example usage: index_subdirectory(directory, class_indices, follow_links, formats) and returns: filenames,  labels