class_docstr: An interface between the Scenic DETR implementation and COCO evaluators.
docstr: Add a single example to the evaluator.
  
  Args:
    prediction: Model prediction dictionary with keys 'pred_img_ids',
      'pred_probs' in shape of `[num_objects, num_classes]` and 'pred_boxes'
      in shape of `[num_objects, 4]`. Box coordinates should be in raw DETR
      format, i.e. [cx, cy, w, h] in range [0, 1].
    target: Target dictionary with keys 'orig_size', 'size', and 'image/id'.
      Must also contain 'padding_mask' if the input image was padded.
docstr_tok: ["Add","a","single","example","to","the","evaluator",".","Args",":","prediction",":","Model","prediction","dictionary","with","keys","'pred_img_ids","'",",","'pred_probs","'","in","shape","of","`","[","num_objects",",","num_classes","]","`","and","'pred_boxes'","in","shape","of","`","[","num_objects",",","4","]","`",".","Box","coordinates","should","be","in","raw","DETR","format",",","i.e",".","[","cx",",","cy",",","w",",","h","]","in","range","[","0",",","1","]",".","target",":","Target","dictionary","with","keys","'orig_size","'",",","'size","'",",","and","'image\/id","'",".","Must","also","contain","'padding_mask","'","if","the","input","image","was","padded","."]
code: def add_example(
      self,
      prediction: Dict[str, np.ndarray],
      target: Dict[str, np.ndarray],
  ):
      """Add a single example to the evaluator.
  
      Args:
        prediction: Model prediction dictionary with keys 'pred_img_ids',
          'pred_probs' in shape of `[num_objects, num_classes]` and 'pred_boxes'
          in shape of `[num_objects, 4]`. Box coordinates should be in raw DETR
          format, i.e. [cx, cy, w, h] in range [0, 1].
        target: Target dictionary with keys 'orig_size', 'size', and 'image/id'.
          Must also contain 'padding_mask' if the input image was padded.
      """
      if "pred_boxes" not in prediction:
          # Add dummy to make eval work:
          prediction = copy.deepcopy(prediction)
          prediction["pred_boxes"] = (
              np.zeros((prediction["pred_logits"].shape[0], 4)) + 0.5
          )
  
      # Convert from DETR [cx, cy, w, h] to COCO [x, y, w, h] bounding box format:
      boxes = box_utils.box_cxcywh_to_xyxy(prediction["pred_boxes"])
      boxes = np.array(boxes)
      boxes[:, 2] -= boxes[:, 0]
      boxes[:, 3] -= boxes[:, 1]
  
      # Scale from relative to absolute size:
      # Note that the padding is implemented such that such that the model's
      # predictions are [0,1] normalized to the non-padded image, so scaling by
      # `orig_size` will convert correctly to the original image coordinates. No
      # image flipping happens during evaluation.
      h, w = np.asarray(target["orig_size"])
      scale_factor = np.array([w, h, w, h])
      boxes = boxes * scale_factor[np.newaxis, :]
      boxes_np = np.asarray(boxes)
  
      # Get scores, excluding the background class:
      if "pred_probs" in prediction:
          scores = prediction["pred_probs"][:, 1:]
      else:
          scores = scipy.special.softmax(
              prediction["pred_logits"], axis=-1
          )[:, 1:]
  
      # Add example to evaluator:
      self.coco_evaluator.add_annotation(
          bboxes=boxes_np,
          scores=np.asarray(scores),
          img_id=int(target["image/id"]),
      )
  
      self._num_examples_added += 1
  
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 2 for calling the DetrGlobalEvaluator obj's underlying member method code with example usage: obj.add_example(prediction, target) without return types