class_docstr: An interface between the Scenic DETR implementation and COCO evaluators.
class_docstr_tok: ["An","interface","between","the","Scenic","DETR","implementation","and","COCO","evaluators","."]
docstr: Computes the metrics for all added predictions.
docstr_tok: ["Computes","the","metrics","for","all","added","predictions","."]
code: def compute_metrics(self) -> Dict[str, Any]:
      """Computes the metrics for all added predictions."""
      results = {}
  
      keys = list(self._labels.keys())
      for key in keys:
          labels = np.array(self._labels[key])
          preds = np.array(self._preds[key])
  
          correct = np.sum(labels == preds)
          accuracy = 0.0
          if self._labels[key]:
              accuracy = correct / len(labels)
  
          labels_onehot = np.zeros((len(labels), self._num_classes))
          labels_onehot[np.arange(labels.size), labels] = 1
          # Remove padding/non-target as we only compute P/R/F for target classes.
          labels_onehot = labels_onehot[:, 2:]
  
          preds_onehot = np.zeros((len(preds), self._num_classes))
          preds_onehot[np.arange(preds.size), preds] = 1
          preds_onehot = preds_onehot[:, 2:]
  
          # We calculate P/R/F for target classes.
          mask = labels > 1
          mask = np.expand_dims(mask, axis=-1)
          p, r, f = multi_class_scores(
              labels_onehot, preds_onehot, mask
          )
  
          task, ds = key
          results.update(
              {
                  f"{task}-{ds}/accuracy": accuracy,
                  f"{task}-{ds}/precision": p,
                  f"{task}-{ds}/recall": r,
                  f"{task}-{ds}/f1": f,
                  f"{task}-{ds}/num_instances": len(labels),
              }
          )
      return results
  
imports: import collections
  import copy
  import functools
  from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union
  from absl import logging
  import flax
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.common_lib import debug_utils
  from scenic.train_lib_deprecated import optimizers
  from scenic.train_lib_deprecated import train_utils
label_desc: Use image node_id 4 for calling the LayoutDenoiseGlobalEvaluator obj's underlying member method code with example usage: obj.compute_metrics() and returns: results