class_docstr: Tests confusion matrix metrics.
docstr: Test calculation of metrics given a confusion matrix.
code: def test_confusion_matrix_metrics(self):
      """Test calculation of metrics given a confusion matrix."""
  
      confusion_matrices = [
          np.array([[[2, 0, 1], [1, 3, 0], [1, 2, 4]]]),
          np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]),
      ]
      metrics = evaluation_lib.compute_confusion_matrix_metrics(
          confusion_matrices, return_per_class_metrics=True
      )
  
      expected_keys = {
          "recall/mean",
          "precision/mean",
          "jaccard/mean",
          "recall/0",
          "recall/1",
          "recall/2",
          "precision/0",
          "precision/1",
          "precision/2",
          "jaccard/0",
          "jaccard/1",
          "jaccard/2",
      }
      self.assertSameElements(expected_keys, metrics.keys())
      self.assertAlmostEqual(
          metrics["recall/mean"], np.mean([3 / 9, 8 / 19, 13 / 31])
      )
      self.assertAlmostEqual(metrics["recall/0"], 3 / 9)
      self.assertAlmostEqual(metrics["recall/1"], 8 / 19)
      self.assertAlmostEqual(metrics["recall/2"], 13 / 31)
      self.assertAlmostEqual(
          metrics["precision/mean"], np.mean([3 / 16, 8 / 20, 13 / 23])
      )
      self.assertAlmostEqual(metrics["precision/0"], 3 / 16)
      self.assertAlmostEqual(metrics["precision/1"], 8 / 20)
      self.assertAlmostEqual(metrics["precision/2"], 13 / 23)
      self.assertAlmostEqual(
          metrics["jaccard/mean"], np.mean([3 / 22, 8 / 31, 13 / 41])
      )
      self.assertAlmostEqual(metrics["jaccard/0"], 3 / 22)
      self.assertAlmostEqual(metrics["jaccard/1"], 8 / 31)
      self.assertAlmostEqual(metrics["jaccard/2"], 13 / 41)
  
file_path: scenic/scenic/projects/vivit/tests/test_vivit_metrics.py
imports: from absl.testing import absltest
  import jax.numpy
  import numpy
  from scenic.projects.vivit import evaluation_lib
  from scenic.projects.vivit import model_utils
label_desc: Use image node_id 1 for calling the ConfusionMatrixTester obj's underlying member method code with example usage: obj.test_confusion_matrix_metrics() without return types