class_docstr:     Calculate precision, recall, F1 for each labels
  
  Parameters
  ----------
  metrics: list
      Indicate the metric for the class to return.
      Note that each metric must be one of ``precision``, ``recall``, ``F1``, ``accuracy``.
      And the results' order is the same as the metrics.
class_docstr_tok: ["Calculate","precision",",","recall",",","F1","for","each","labels","Parameters","--","--","--","--","--","metrics",":","list","Indicate","the","metric","for","the","class","to","return",".","Note","that","each","metric","must","be","one","of","``","precision","``",",","``","recall","``",",","``","F1","``",",","``","accuracy","``",".","And","the","results","'","order","is","the","same","as","the","metrics","."]
docstr:     The function to calculate the confusion matrix for multi-class inputs.
      The labels will be collected and relabeled. (eg: [1, 2, 3] --> [0, 1, 2])
  
      In multi-class confusion matrix :math:`MCM`, the count of true negatives is
      :math:`MCM_{:,0,0}`, false positives is :math:`MCM_{:,0,1}`, false negatives
      is :math:`MCM_{:,1,0}` and true positive is :math:`MCM_{:,1,1}`.
  
  Parameters
  ----------
  ground_truth: numpy.ndarray
  predict: numpy.ndarray
  
  Returns
  -------
  confusion_matrix: numpy.ndarray
      The confusion matrix which has the shape: [num_labels, 2, 2]
docstr_tok: ["The","function","to","calculate","the","confusion","matrix","for","multi-class","inputs",".","The","labels","will","be","collected","and","relabeled",".","(","eg",":","[","1",",","2",",","3","]","--",">","[","0",",","1",",","2","]",")","In","multi-class","confusion","matrix",":","math",":","`","MCM","`",",","the","count","of","true","negatives","is",":","math",":","`","MCM_","{",":",",0,0","}","`",",","false","positives","is",":","math",":","`","MCM_","{",":",",0,1","}","`",",","false","negatives","is",":","math",":","`","MCM_","{",":",",1,0","}","`","and","true","positive","is",":","math",":","`","MCM_","{",":",",1,1","}","`",".","Parameters","--","--","--","--","--","ground_truth",":","numpy.ndarray","predict",":","numpy.ndarray","Returns","--","--","--","-","confusion_matrix",":","numpy.ndarray","The","confusion","matrix","which","has","the","shape",":","[","num_labels",",","2",",","2","]"]
code: def _calculate_confusion_matrix(self, ground_truth, predict):
      """
          The function to calculate the confusion matrix for multi-class inputs.
          The labels will be collected and relabeled. (eg: [1, 2, 3] --> [0, 1, 2])
  
          In multi-class confusion matrix :math:`MCM`, the count of true negatives is
          :math:`MCM_{:,0,0}`, false positives is :math:`MCM_{:,0,1}`, false negatives
          is :math:`MCM_{:,1,0}` and true positive is :math:`MCM_{:,1,1}`.
  
      Parameters
      ----------
      ground_truth: numpy.ndarray
      predict: numpy.ndarray
  
      Returns
      -------
      confusion_matrix: numpy.ndarray
          The confusion matrix which has the shape: [num_labels, 2, 2]
      """
      # select all labels, remove duplicates and sort
      unique_labels = sorted(
          self._get_unique_labels(ground_truth, predict)
      )
  
      # do relabeling
      ground_truth_transformed = np.searchsorted(
          unique_labels, ground_truth
      )
      predict_transformed = np.searchsorted(unique_labels, predict)
  
      # the number of labels after relabeling
      n_labels = len(unique_labels)
  
      tp = ground_truth_transformed == predict_transformed
      tp_bins = ground_truth_transformed[tp]
      tp_sum = np.bincount(tp_bins, weights=None, minlength=n_labels)
      pred_sum = np.bincount(predict_transformed, minlength=n_labels)
      gt_sum = np.bincount(ground_truth_transformed, minlength=n_labels)
      fp = pred_sum - tp_sum
      fn = gt_sum - tp_sum
      tp = tp_sum
      tn = ground_truth_transformed.shape[0] - tp - fp - fn
      return np.array([tn, fp, fn, tp]).T.reshape(-1, 2, 2)
  
file_path: graph4nlp/graph4nlp/pytorch/modules/evaluation/accuracy.py
imports: import copy
  import warnings
  import numpy
  import torch
  from graph4nlp.pytorch.modules.evaluation.base import EvaluationMetricBase
label_desc: Use image node_id 5 for calling the Accuracy obj's underlying member method code with example usage: obj._calculate_confusion_matrix(ground_truth, predict) and returns: np