Yields examples.

def _generate_example(self, data_path, image_id):
    """Yields examples."""
    image_filepath = os.path.join(
        data_path, "VOCdevkit/VOC2007/JPEGImages", "{}.jpg".format(image_id))
    annon_filepath = os.path.join(
        data_path, "VOCdevkit/VOC2007/Annotations", "{}.xml".format(image_id))

    def _get_example_objects():
      """Function to get all the objects from the annotation XML file."""
      with tf.io.gfile.GFile(annon_filepath, "r") as f:
        root = xml.etree.ElementTree.parse(f).getroot()

        size = root.find("size")
        width = float(size.find("width").text)
        height = float(size.find("height").text)

        for obj in root.findall("object"):
          # Get object's label name.
          label = obj.find("name").text.lower()
          # Get objects' pose name.
          pose = obj.find("pose").text.lower()
          is_truncated = (obj.find("truncated").text == "1")
          is_difficult = (obj.find("difficult").text == "1")
          bndbox = obj.find("bndbox")
          xmax = float(bndbox.find("xmax").text)
          xmin = float(bndbox.find("xmin").text)
          ymax = float(bndbox.find("ymax").text)
          ymin = float(bndbox.find("ymin").text)
          yield {
              "label": label,
              "pose": pose,
              "bbox": tfds.features.BBox(
                  ymin / height, xmin / width, ymax / height, xmax / width),
              "is_truncated": is_truncated,
              "is_difficult": is_difficult,
          }

    objects = list(_get_example_objects())
    # Use set() to remove duplicates
    labels = sorted(set(obj["label"] for obj in objects))
    labels_no_difficult = sorted(set(
        obj["label"] for obj in objects if obj["is_difficult"] == 0
    ))
    return {
        "image": image_filepath,
        "image/filename": image_id + ".jpg",
        "objects": objects,
        "labels": labels,
        "labels_no_difficult": labels_no_difficult,
    }