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: Construct the `DatasetBuilder`.
  
  Args:
    root_dir: Path to the directory containing the images.
    shape: Image shape forwarded to `tfds.features.Image`.
    dtype: Image dtype forwarded to `tfds.features.Image`.
docstr_tok: ["Construct","the","`","DatasetBuilder","`",".","Args",":","root_dir",":","Path","to","the","directory","containing","the","images",".","shape",":","Image","shape","forwarded","to","`","tfds.features.Image","`",".","dtype",":","Image","dtype","forwarded","to","`","tfds.features.Image","`","."]
code: def __init__(
      self,
      root_dir: str,
      *,
      shape: Optional[type_utils.Shape] = None,
      dtype: Optional[tf.DType] = None,
  ):
      """Construct the `DatasetBuilder`.
  
      Args:
        root_dir: Path to the directory containing the images.
        shape: Image shape forwarded to `tfds.features.Image`.
        dtype: Image dtype forwarded to `tfds.features.Image`.
      """
      self._image_shape = shape
      self._image_dtype = dtype
      super(ImageFolder, self).__init__()
      self._data_dir = root_dir  # Set data_dir to the existing dir.
  
      # Extract the splits, examples, labels
      root_dir = os.path.expanduser(root_dir)
      self._split_examples, labels = _get_split_label_images(root_dir)
  
      # Update DatasetInfo labels
      self.info.features["label"].names = sorted(labels)
  
      # Update DatasetInfo splits
      split_infos = [
          split_lib.SplitInfo(  # pylint: disable=g-complex-comprehension
              name=split_name,
              shard_lengths=[len(examples)],
              num_bytes=0,
          )
          for split_name, examples in self._split_examples.items()
      ]
      split_dict = split_lib.SplitDict(split_infos)
      self.info.set_splits(split_dict)
  
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 1 to create a new ImageFolder object from inherited base classes: dataset_builder with example: obj = ImageFolder(root_dir)