code: def test_multiclass_images():
      num_classes = 3
      cm = ConfusionMatrix(num_classes=num_classes)
  
      y_true, y_pred = get_y_true_y_pred()
  
      # Compute confusion matrix with sklearn
      true_res = confusion_matrix(
          y_true.reshape(-1), y_pred.reshape(-1)
      )
  
      th_y_true, th_y_logits = compute_th_y_true_y_logits(
          y_true, y_pred
      )
  
      # Update metric
      output = (th_y_logits, th_y_true)
      cm.update(output)
  
      res = cm.compute().numpy()
  
      assert np.all(true_res == res)
  
      # Another test on batch of 2 images
      num_classes = 3
      cm = ConfusionMatrix(num_classes=num_classes)
  
      # Create a batch of two images:
      th_y_true1 = torch.from_numpy(y_true).reshape(1, 30, 30)
      th_y_true2 = torch.from_numpy(y_true.transpose()).reshape(
          1, 30, 30
      )
      th_y_true = torch.cat([th_y_true1, th_y_true2], dim=0)
  
      # Create a batch of 2 logits tensors
      y_probas = np.ones((3, 30, 30)) * -10
      y_probas[0, (y_pred == 0)] = 720
      y_probas[1, (y_pred == 1)] = 720
      y_probas[2, (y_pred == 2)] = 768
      th_y_logits1 = torch.from_numpy(y_probas).reshape(1, 3, 30, 30)
  
      y_probas = np.ones((3, 30, 30)) * -10
      y_probas[0, (y_pred.transpose() == 0)] = 720
      y_probas[1, (y_pred.transpose() == 2)] = 720
      y_probas[2, (y_pred.transpose() == 1)] = 768
      th_y_logits2 = torch.from_numpy(y_probas).reshape(1, 3, 30, 30)
  
      th_y_logits = torch.cat([th_y_logits1, th_y_logits2], dim=0)
  
      # Update metric & compute
      output = (th_y_logits, th_y_true)
      cm.update(output)
      res = cm.compute().numpy()
  
      # Compute confusion matrix with sklearn
      true_res = confusion_matrix(
          th_y_true.numpy().reshape(-1),
          np.argmax(th_y_logits.numpy(), axis=1).reshape(-1),
      )
  
      assert np.all(true_res == res)
  
imports: import os
  import numpy
  import pytest
  import torch
  from sklearn.metrics import accuracy_score, confusion_matrix, precision_score, recall_score
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics import ConfusionMatrix, IoU, JaccardIndex, mIoU
  from ignite.metrics.confusion_matrix import cmAccuracy, cmPrecision, cmRecall, DiceCoefficient
label_desc: Use image node_id 9 for calling a global function with example usage: test_multiclass_images() without return types