code: def _create_per_track_annotation(
      track,
      track_to_anns: NestedDict,
      anns_to_image: NestedDict,
      height: int,
      width: int,
  ) -> NestedDict:
      """Prepares annotation for a single track within a video."""
      per_track_anno = {}
      per_track_anno["bboxes"] = []
      per_track_anno["frames"] = []
      track_annos = track_to_anns[track["id"]]
      assert (
          len(np.unique([a["category_id"] for a in track_annos])) == 1
      )
      assert (
          len(np.unique([a["scale_category"] for a in track_annos]))
          == 1
      )
      assert len(np.unique([a["iscrowd"] for a in track_annos])) == 1
      per_track_anno["category"] = track["category_id"]
      per_track_anno["is_crowd"] = track_annos[0]["iscrowd"]
      per_track_anno["scale_category"] = track_annos[0][
          "scale_category"
      ]
      per_track_anno["track_id"] = track["id"]
      for ann in track_to_anns[track["id"]]:
          # NOTE: Some bbox annotations extend off the boundary of the image.
          # Below we clip them to lie within the image boundaries.
          ymin = max(0.0, ann["bbox"][1] / height)
          ymax = min(1.0, (ann["bbox"][1] + ann["bbox"][3]) / height)
          xmin = max(0.0, ann["bbox"][0] / width)
          xmax = min(1.0, (ann["bbox"][0] + ann["bbox"][2]) / width)
          per_track_anno["bboxes"].append(
              tfds.features.BBox(
                  ymin=ymin, ymax=ymax, xmin=xmin, xmax=xmax
              )
          )
          per_track_anno["frames"].append(
              anns_to_image[ann["id"]]["frame_index"]
          )
  
      # Frame indices should be sorted.
      assert all(
          per_track_anno["frames"][i - 1] <= per_track_anno["frames"][i]
          for i in range(1, len(per_track_anno["frames"]))
      )
      return per_track_anno
  
imports: from __future__ import annotations
  import collections
  import json
  import os
  from typing import Any, Dict, Optional, Tuple
  from etils import epath
  import numpy
  import tensorflow_datasets.public_api
label_desc: Use image node_id 6 for calling a global function with example usage: _create_per_track_annotation(track, track_to_anns, anns_to_image, height, width) and returns: per_track_anno