code: def testConfusionMeter(self):
      mtr = meter.ConfusionMeter(k=3)
  
      output = torch.Tensor(
          [[0.8, 0.1, 0.1], [10, 11, 10], [0.2, 0.2, 0.3]]
      )
      target = torch.range(0, 2)
      mtr.add(output, target)
  
      conf_mtrx = mtr.value()
      self.assertEqual(conf_mtrx.sum(), 3, "All should be correct")
      self.assertEqual(
          conf_mtrx.diagonal().sum(), 3, "All should be correct"
      )
  
      target = torch.Tensor([1, 0, 0])
      mtr.add(output, target)
  
      self.assertEqual(
          conf_mtrx.sum(), 6, "Six tests should give six values"
      )
      self.assertEqual(
          conf_mtrx.diagonal().sum(),
          3,
          "Shouldn't have changed since all new values were false",
      )
      self.assertEqual(
          conf_mtrx[0].sum(), 3, "All top have gotten one guess"
      )
      self.assertEqual(
          conf_mtrx[1].sum(), 2, "Two first at the 2nd row have a guess"
      )
      self.assertEqual(
          conf_mtrx[1][2], 0, "The last one should be empty"
      )
      self.assertEqual(
          conf_mtrx[2].sum(),
          1,
          "Bottom row has only the first test correct",
      )
      self.assertEqual(
          conf_mtrx[2][2],
          1,
          "Bottom row has only the first test correct",
      )
  
      mtr = meter.ConfusionMeter(k=4, normalized=True)
      output = torch.Tensor(
          [
              [0.8, 0.1, 0.1, 0],
              [10, 11, 10, 0],
              [0.2, 0.2, 0.3, 0],
              [0, 0, 0, 1],
          ]
      )
  
      target = torch.Tensor([0, 1, 2, 3])
      mtr.add(output, target)
      conf_mtrx = mtr.value()
  
      self.assertEqual(
          conf_mtrx.sum(), output.size(1), "All should be correct"
      )
      self.assertEqual(
          conf_mtrx.diagonal().sum(),
          output.size(1),
          "All should be correct",
      )
  
      target[0] = 1
      target[1] = 0
      target[2] = 0
  
      mtr.add(output, target)
      conf_mtrx = mtr.value()
  
      self.assertEqual(
          conf_mtrx.sum(),
          output.size(1),
          "The normalization should sum all values to 1",
      )
      for i, row in enumerate(conf_mtrx):
          self.assertEqual(
              row.sum(),
              1,
              "Row no "
              + str(i)
              + " fails to sum to one in normalized mode",
          )
  
file_path: pywick/tests/test_meters.py
imports: import unittest
  import math
  import torch
  import pywick.meters
  import numpy
label_desc: Use image node_id 3 for calling the TestMeters obj's underlying member method code with example usage: obj.testConfusionMeter() without return types