class_docstr: CacheFilesWriter class to write the cached files for COCO data.
class_docstr_tok: ["CacheFilesWriter","class","to","write","the","cached","files","for","COCO","data","."]
docstr: Iterates over all examples in the COCO formatted dataset directory.
  
  Args:
    data_dir: Path of the dataset directory
  
  Yields:
    tf.train.Example
docstr_tok: ["Iterates","over","all","examples","in","the","COCO","formatted","dataset","directory",".","Args",":","data_dir",":","Path","of","the","dataset","directory","Yields",":","tf.train.Example"]
code: def _get_example(self, data_dir: str) -> tf.train.Example:
      """Iterates over all examples in the COCO formatted dataset directory.
  
      Args:
        data_dir: Path of the dataset directory
  
      Yields:
        tf.train.Example
      """
      data_dir = os.path.abspath(data_dir)
      # Process labels.json file
      label_file = os.path.join(data_dir, "labels.json")
      with open(label_file, "r") as f:
          data = json.load(f)
  
      # Load all Annotations
      img_to_annotations = collections.defaultdict(list)
      for annotation in data["annotations"]:
          image_id = annotation["image_id"]
          img_to_annotations[image_id].append(annotation)
  
      # For each Image:
      for image in data["images"]:
          img_id = image["id"]
          file_name = image["file_name"]
          full_path = os.path.join(data_dir, "images", file_name)
          with tf.io.gfile.GFile(full_path, "rb") as fid:
              encoded_jpg = fid.read()
          image = tf.io.decode_jpeg(encoded_jpg, channels=3)
          height, width, _ = image.shape
          feature_dict = tfrecord_lib.image_info_to_feature_dict(
              height, width, file_name, img_id, encoded_jpg, "jpg"
          )
          data, _ = _coco_annotations_to_lists(
              img_to_annotations[img_id], height, width
          )
          if not data["xmin"]:
              # Skip examples which have no annotations
              continue
          bbox_feature_dict = _bbox_data_to_feature_dict(data)
          feature_dict.update(bbox_feature_dict)
          example = tf.train.Example(
              features=tf.train.Features(feature=feature_dict)
          )
          yield example
  
imports: import abc
  import collections
  import hashlib
  import json
  import math
  import os
  import tempfile
  from typing import Any, Dict, List, Mapping, Optional
  import xml.etree.ElementTree
  import tensorflow
  from mediapipe.model_maker.python.core.data import cache_files
  from official.vision.data import tfrecord_lib
label_desc: Use image node_id 1 for calling the COCOCacheFilesWriter obj's underlying member method code with example usage: obj._get_example(data_dir) without return types