code: def get_confusion_matrix(
      preds, labels, num_classes, normalize="true"
  ):
      """
      Calculate confusion matrix on the provided preds and labels.
      Args:
          preds (tensor or lists of tensors): predictions. Each tensor is in
              in the shape of (n_batch, num_classes). Tensor(s) must be on CPU.
          labels (tensor or lists of tensors): corresponding labels. Each tensor is
              in the shape of either (n_batch,) or (n_batch, num_classes).
          num_classes (int): number of classes. Tensor(s) must be on CPU.
          normalize (Optional[str]) : {‘true’, ‘pred’, ‘all’}, default="true"
              Normalizes confusion matrix over the true (rows), predicted (columns)
              conditions or all the population. If None, confusion matrix
              will not be normalized.
      Returns:
          cmtx (ndarray): confusion matrix of size (num_classes x num_classes)
      """
      if isinstance(preds, list):
          preds = torch.cat(preds, dim=0)
      if isinstance(labels, list):
          labels = torch.cat(labels, dim=0)
      # If labels are one-hot encoded, get their indices.
      if labels.ndim == preds.ndim:
          labels = torch.argmax(labels, dim=-1)
      # Get the predicted class indices for examples.
      preds = torch.flatten(torch.argmax(preds, dim=-1))
      labels = torch.flatten(labels)
      cmtx = confusion_matrix(
          labels,
          preds,
          labels=list(range(num_classes)),
          normalize=normalize,
      )
      return cmtx
  
imports: import itertools
  import numpy
  import matplotlib.pyplot
  import torch
  from sklearn.metrics import confusion_matrix
  import slowfast.utils.logging
  from slowfast.datasets.utils import pack_pathway_output, tensor_normalize
label_desc: Use image node_id 1 for calling a global function with example usage: get_confusion_matrix(preds, labels, num_classes, normalize) and returns: cmtx