class_docstr: Generic image classification dataset created from manual directory.
  
  `ImageFolder` creates a `tf.data.Dataset` reading the original image files.
  
  The data directory should have the following structure:
  
  ```
  path/to/image_dir/
    split_name/  # Ex: 'train'
      label1/  # Ex: 'airplane' or '0015'
        xxx.png
        xxy.png
        xxz.png
      label2/
        xxx.png
        xxy.png
        xxz.png
    split_name/  # Ex: 'test'
      ...
  ```
  
  To use it:
  
  ```
  builder = tfds.ImageFolder('path/to/image_dir/')
  print(builder.info)  # num examples, labels... are automatically calculated
  ds = builder.as_dataset(split='train', shuffle_files=True)
  tfds.show_examples(ds, builder.info)
  ```
class_docstr_tok: ["Generic","image","classification","dataset","created","from","manual","directory",".","`","ImageFolder","`","creates","a","`","tf.data.Dataset","`","reading","the","original","image","files",".","The","data","directory","should","have","the","following","structure",":","``","`","path\/to\/image_dir\/","split_name\/","#","Ex",":","'train'","label1\/","#","Ex",":","'airplane","'","or","'0015'","xxx.png","xxy.png","xxz.png","label2\/","xxx.png","xxy.png","xxz.png","split_name\/","#","Ex",":","'test'","...","``","`","To","use","it",":","``","`","builder","=","tfds.ImageFolder","(","'path\/to\/image_dir\/","'",")","print","(","builder.info",")","#","num","examples",",","labels","...","are","automatically","calculated","ds","=","builder.as_dataset","(","split='train","'",",","shuffle_files=True",")","tfds.show_examples","(","ds",",","builder.info",")","``","`"]
docstr: Generate dataset for given split.
docstr_tok: ["Generate","dataset","for","given","split","."]
code: def _as_dataset(
      self,
      split: str,
      shuffle_files: bool = False,
      decoders: Optional[Dict[str, decode.Decoder]] = None,
      read_config=None,
  ) -> tf.data.Dataset:
      """Generate dataset for given split."""
      del read_config  # Unused (automatically created in `DatasetBuilder`)
  
      if split not in self.info.splits.keys():
          raise ValueError(
              "Unrecognized split {}. Subsplit API not yet supported for {}. "
              "Split name should be one of {}.".format(
                  split,
                  type(self).__name__,
                  list(self.info.splits.keys()),
              )
          )
  
      # Extract all labels/images
      image_paths = []
      labels = []
      examples = self._split_examples[split]
      for example in examples:
          image_paths.append(example.image_path)
          labels.append(
              self.info.features["label"].str2int(example.label)
          )
  
      # Build the tf.data.Dataset object
      ds = tf.data.Dataset.from_tensor_slices((image_paths, labels))
      if shuffle_files:
          ds = ds.shuffle(len(examples))
  
      # Fuse load and decode into one function
      def _load_and_decode_fn(*args, **kwargs):
          ex = _load_example(*args, **kwargs)
          return self.info.features.decode_example(
              ex, decoders=decoders
          )
  
      ds = ds.map(
          _load_and_decode_fn,
          num_parallel_calls=tf.data.experimental.AUTOTUNE,
      )
      return ds
  
imports: from __future__ import annotations
  import collections
  import os
  import random
  from typing import Dict, List, NoReturn, Optional, Tuple
  from tensorflow_datasets.core import dataset_builder
  from tensorflow_datasets.core import dataset_info
  from tensorflow_datasets.core import decode
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core.utils import type_utils
  from tensorflow_datasets.core.utils import version
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 5 for calling the ImageFolder obj's underlying member method code with example usage: obj._as_dataset(split, shuffle_files, decoders, read_config) and returns: ds, self