code: def image_dataset_from_directory(
      directory: str,
      batch_size: int = 32,
      color_mode: str = "rgb",
      image_size: Tuple[int, int] = (256, 256),
      interpolation: str = "bilinear",
      shuffle: bool = True,
      seed: Optional[int] = None,
      validation_split: Optional[float] = None,
      subset: Optional[str] = None,
  ) -> tf.data.Dataset:
      """Generates a `tf.data.Dataset` from image files in a directory.
      If your directory structure is:
  
      ```
      main_directory/
      ...class_a/
      ......a_image_1.jpg
      ......a_image_2.jpg
      ...class_b/
      ......b_image_1.jpg
      ......b_image_2.jpg
      ```
  
      Then calling `image_dataset_from_directory(main_directory)`
      will return a `tf.data.Dataset` that yields batches of images from
      the subdirectories `class_a` and `class_b`, together with labels
      'class_a' and 'class_b'.
  
      Supported image formats: jpeg, png, bmp, gif.
      Animated gifs are truncated to the first frame.
  
      # Arguments
          directory: Directory where the data is located.
              If `labels` is "inferred", it should contain
              subdirectories, each containing images for a class.
              Otherwise, the directory structure is ignored.
          batch_size: Size of the batches of data. Default: 32.
          color_mode: One of "grayscale", "rgb", "rgba". Default: "rgb".
              Whether the images will be converted to
              have 1, 3, or 4 channels.
          image_size: Size to resize images to after they are read from disk.
              Defaults to `(256, 256)`.
              Since the pipeline processes batches of images that must all have
              the same size, this must be provided.
          interpolation: String, the interpolation method used when resizing
              images. Defaults to `bilinear`. Supports `bilinear`, `nearest`,
              `bicubic`, `area`, `lanczos3`, `lanczos5`, `gaussian`,
              `mitchellcubic`.
          shuffle: Whether to shuffle the data. Default: True.
              If set to False, sorts the data in alphanumeric order.
          seed: Optional random seed for shuffling and transformations.
          validation_split: Optional float between 0 and 1,
              fraction of data to reserve for validation.
          subset: One of "training" or "validation".
              Only used if `validation_split` is set.
  
      # Returns
          A `tf.data.Dataset` object, which yields a tuple `(texts, labels)`,
          where `images` has shape `(batch_size, image_size[0], image_size[1],
          num_channels)` where `labels` has shape `(batch_size,)` and type of
          tf.string.
          - if `color_mode` is `grayscale`, there's 1 channel in the image
          tensors.
          - if `color_mode` is `rgb`, there are 3 channel in the image tensors.
          - if `color_mode` is `rgba`, there are 4 channel in the image tensors.
      """
      if color_mode == "rgb":
          num_channels = 3
      elif color_mode == "rgba":
          num_channels = 4
      elif color_mode == "grayscale":
          num_channels = 1
      else:
          raise ValueError(
              '`color_mode` must be one of {"rbg", "rgba", "grayscale"}. '
              "Received: %s" % (color_mode,)
          )
  
      if seed is None:
          seed = np.random.randint(1e6)
      image_paths, labels, class_names = index_directory(
          directory,
          "inferred",
          formats=WHITELIST_FORMATS,
          shuffle=shuffle,
          seed=seed,
      )
  
      image_paths, labels = get_training_or_validation_split(
          image_paths, labels, validation_split, subset
      )
  
      images = tf.data.Dataset.from_tensor_slices(image_paths)
      images = images.map(
          lambda img: path_to_image(
              img, num_channels, image_size, interpolation
          )
      )
  
      labels = np.array(class_names)[np.array(labels)]
      labels = tf.data.Dataset.from_tensor_slices(labels)
  
      dataset = tf.data.Dataset.zip((images, labels))
      dataset = dataset.batch(batch_size)
      return dataset
  
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 8 for calling a global function with example usage: image_dataset_from_directory(directory, batch_size, color_mode, image_size, interpolation, shuffle, seed, validation_split, subset) and returns: dataset