class_docstr: An interface between the Scenic DETR implementation and COCO evaluators.
docstr: Writes predictions to file in JSON format.
  
  Args:
    path: Path to write the prediction annotation JSON file.
    fname_app: Optional string to append to the file name.
    clear_annotations: Clear annotations after they are stored in a file.
docstr_tok: ["Writes","predictions","to","file","in","JSON","format",".","Args",":","path",":","Path","to","write","the","prediction","annotation","JSON","file",".","fname_app",":","Optional","string","to","append","to","the","file","name",".","clear_annotations",":","Clear","annotations","after","they","are","stored","in","a","file","."]
code: def write_pred_annotations_to_file(
      self,
      path: str,
      fname_app: Optional[str] = None,
      clear_annotations: Optional[bool] = True,
  ):
      """Writes predictions to file in JSON format.
  
      Args:
        path: Path to write the prediction annotation JSON file.
        fname_app: Optional string to append to the file name.
        clear_annotations: Clear annotations after they are stored in a file.
      """
      if not tf.io.gfile.exists(path):
          tf.io.gfile.makedirs(path)
      json_file_name = (
          f"predictions{fname_app if fname_app else ''}.json"
      )
      json_file_path = os.path.join(path, json_file_name)
  
      def _convert_to_serializable(obj):
          if isinstance(obj, np.ndarray):
              return obj.tolist()
          elif isinstance(obj, np.float32):
              return float(obj)
          else:
              raise TypeError(
                  f"Unserializable object {obj} of type {type(obj)}"
              )
  
      with tf.io.gfile.GFile(json_file_path, "w") as f:
          f.write(
              json.dumps(
                  self.coco_evaluator.annotations,
                  default=_convert_to_serializable,
              )
          )
      logging.info(
          "Predicted annotations are stored in %s.", json_file_path
      )
      if clear_annotations:
          self.coco_evaluator.clear_annotations()
  
imports: import copy
  import json
  import os
  from typing import Any, Dict, Optional, Set
  from absl import logging
  from flax import core
  from flax import optim
  from flax import traverse_util
  import jax
  from jax.example_libraries import optimizers
  import jax.numpy
  import numpy
  import PIL
  import PIL.ImageDraw
  import PIL.ImageFont
  from scenic.common_lib import image_utils
  from scenic.dataset_lib.coco_dataset import coco_eval
  from scenic.model_lib.base_models import box_utils
  from scenic.train_lib_deprecated import optimizers
  from scenic.train_lib_deprecated import train_utils
  import scipy.special
  import tensorflow
label_desc: Use image node_id 6 for calling the DetrGlobalEvaluator obj's underlying member method code with example usage: obj.write_pred_annotations_to_file(path, fname_app, clear_annotations) and returns: obj, float