class_docstr: Dataset from the INaturalist Competition 2017.
docstr: Generate examples.
docstr_tok: ["Generate","examples","."]
code: def _generate_examples(self, images_archive, annon_file):
      """Generate examples."""
      if annon_file is not None:
          # Training and validation images.
          with tf.io.gfile.GFile(annon_file, "r") as f:
              data = json.load(f)
          # First read the annotations file, used to filter the contents of the
          # tar.gz file when yielding examples.
          key2data = {}
          for image, annotation in zip(
              data["images"], data["annotations"]
          ):
              category_id = annotation["category_id"]
              category = data["categories"][category_id]["name"]
              supercategory = data["categories"][category_id][
                  "supercategory"
              ]
              key = os.path.basename(image["file_name"]).split(".")[0]
              key2data[key] = {
                  "id": key,
                  "label": category,
                  "supercategory": supercategory,
              }
          # Read tar.gz file containing train & validation images and yield relevant
          # examples.
          for fpath, fobj in images_archive:
              key = os.path.basename(fpath).split(".")[0]
              if key in key2data:
                  data = key2data[key].copy()
                  data["image"] = fobj
                  yield key, data
      else:
          # Read tar.gz file containing all test images and yield all examples.
          for fpath, fobj in images_archive:
              key = os.path.basename(fpath).split(".")[0]
              # Note: test labels are not annotated, so just return -1 as labels.
              yield key, {
                  "id": key,
                  "image": fobj,
                  "label": -1,
                  "supercategory": -1,
              }
  
file_path: datasets/tensorflow_datasets/image_classification/inaturalist.py
imports: import json
  import os
  import six.moves.urllib
  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 INaturalist2017 obj's underlying member method code with example usage: obj._generate_examples(images_archive, annon_file) without return types