class_docstr: DatasetBuilder for iNaturalist 2021 Competition dataset.
docstr: Generate examples.
docstr_tok: ["Generate","examples","."]
code: def _generate_examples(self, images_archive, json_file):
      """Generate examples."""
      # Training and validation images.
      with epath.Path(json_file).open("r") as f:
          inat_json = json.load(f)
  
      def _format(label: str):
          return label.lower().replace(" ", "_")
  
      def _get_annotation(idx, image_id):
          if "annotations" in inat_json:
              annotation = inat_json["annotations"][idx]
              assert annotation["image_id"] == image_id
              cat = inat_json["categories"][annotation["category_id"]]
              category = _format(cat["name"])
              supercategory = _format(cat["supercategory"])
          else:
              category, supercategory = -1, -1
          return category, supercategory
  
      fileid2data = {}
      for idx, image in enumerate(inat_json["images"]):
          category, supercategory = _get_annotation(idx, image["id"])
          fileid = os.path.basename(image["file_name"]).split(".")[0]
          fileid2data[fileid] = {
              "id": image["id"],
              "file_id": fileid,
              "label": category,
              "supercategory": supercategory,
          }
  
      # Read tar.gz file containing images and yield relevant examples.
      for fpath, fobj in images_archive:
          fileid = os.path.basename(fpath).split(".")[0]
          if fileid in fileid2data:
              data = fileid2data[fileid].copy()
              data["image"] = fobj
              yield data["id"], data
  
file_path: datasets/tensorflow_datasets/image_classification/i_naturalist2021/i_naturalist2021.py
imports: import json
  import os
  from etils import epath
  import numpy
  import tensorflow_datasets.public_api
label_desc: Use image node_id 3 for calling the INaturalist2021 obj's underlying member method code with example usage: obj._generate_examples(images_archive, json_file) and returns: label, category,  supercategory