code: def get_confusion_matrix(gt_label, pred_label, num_classes):
      """
      Calcute the confusion matrix by given label and pred
      :param gt_label: the ground truth label
      :param pred_label: the pred label
      :param num_classes: the nunber of class
      :return: the confusion matrix
      """
      index = (gt_label * num_classes + pred_label).astype("int32")
      label_count = np.bincount(index)
      confusion_matrix = np.zeros((num_classes, num_classes))
  
      for i_label in range(num_classes):
          for i_pred_label in range(num_classes):
              cur_index = i_label * num_classes + i_pred_label
              if cur_index < len(label_count):
                  confusion_matrix[i_label, i_pred_label] = label_count[
                      cur_index
                  ]
  
      return confusion_matrix
  
file_path: insightface/parsing/dml_csr/utils/miou.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import cv2
  import json
  import numpy
  import os
  from collections import OrderedDict
  from PIL import Image
  from utils.transforms import transform_parsing
label_desc: Use image node_id 2 for calling a global function with example usage: get_confusion_matrix(gt_label, pred_label, num_classes) and returns: confusion_matrix