class_docstr: Caltech-101.
docstr: Generates images and labels given the image directory path.
  
  As is usual for this dataset, 30 random examples from each class are added
  to the train split, and the remainder are added to the test split.
  
  Args:
    images_dir_path: path to the directory where the images are stored.
    is_train_split: bool, if true, generates the train split, else generates
      the test split.
  
  Yields:
    The image path, and its corresponding label and filename.
  
  Raises:
    ValueError: If too few points are present to create the train set for any
      class.
docstr_tok: ["Generates","images","and","labels","given","the","image","directory","path",".","As","is","usual","for","this","dataset",",","30","random","examples","from","each","class","are","added","to","the","train","split",",","and","the","remainder","are","added","to","the","test","split",".","Args",":","images_dir_path",":","path","to","the","directory","where","the","images","are","stored",".","is_train_split",":","bool",",","if","true",",","generates","the","train","split",",","else","generates","the","test","split",".","Yields",":","The","image","path",",","and","its","corresponding","label","and","filename",".","Raises",":","ValueError",":","If","too","few","points","are","present","to","create","the","train","set","for","any","class","."]
code: def _generate_examples(self, images_dir_path, is_train_split):
      """Generates images and labels given the image directory path.
  
      As is usual for this dataset, 30 random examples from each class are added
      to the train split, and the remainder are added to the test split.
  
      Args:
        images_dir_path: path to the directory where the images are stored.
        is_train_split: bool, if true, generates the train split, else generates
          the test split.
  
      Yields:
        The image path, and its corresponding label and filename.
  
      Raises:
        ValueError: If too few points are present to create the train set for any
          class.
      """
      # Sets random seed so the random partitioning of files is the same when
      # called for the train and test splits.
      numpy_original_state = np.random.get_state()
      np.random.seed(1234)
  
      parent_dir = tf.io.gfile.listdir(images_dir_path)[0]
      walk_dir = os.path.join(images_dir_path, parent_dir)
      dirs = tf.io.gfile.listdir(walk_dir)
  
      for d in dirs:
          # Each directory contains all the images from a single class.
          if tf.io.gfile.isdir(os.path.join(walk_dir, d)):
              for full_path, _, fnames in tf.io.gfile.walk(
                  os.path.join(walk_dir, d)
              ):
                  # _TRAIN_POINTS_PER_CLASS datapoints are sampled for the train split,
                  # the others constitute the test split.
                  if _TRAIN_POINTS_PER_CLASS > len(fnames):
                      raise ValueError(
                          "Fewer than {} ({}) points in class {}".format(
                              _TRAIN_POINTS_PER_CLASS, len(fnames), d
                          )
                      )
                  train_fnames = np.random.choice(
                      fnames, _TRAIN_POINTS_PER_CLASS, replace=False
                  )
                  test_fnames = set(fnames).difference(train_fnames)
                  fnames_to_emit = (
                      train_fnames if is_train_split else test_fnames
                  )
  
                  for image_file in fnames_to_emit:
                      if image_file.endswith(".jpg"):
                          image_path = os.path.join(
                              full_path, image_file
                          )
                          record = {
                              "image": image_path,
                              "label": d.lower(),
                              "image/file_name": image_file,
                          }
                          yield "%s/%s" % (d, image_file), record
      # Resets the seeds to their previous states.
      np.random.set_state(numpy_original_state)
  
file_path: datasets/tensorflow_datasets/datasets/caltech101/caltech101_dataset_builder.py
imports: import os
  import numpy
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 3 for calling the Builder obj's underlying member method code with example usage: obj._generate_examples(images_dir_path, is_train_split) without return types