code: def calculate_area(pred, label, num_classes, ignore_index=255):
      """
      Calculate intersect, prediction and label area
  
      Args:
          pred (Tensor): The prediction by model.
          label (Tensor): The ground truth of image.
          num_classes (int): The unique number of target classes.
          ignore_index (int): Specifies a target value that is ignored. Default: 255.
  
      Returns:
          Tensor: The intersection area of prediction and the ground on all class.
          Tensor: The prediction area on all class.
          Tensor: The ground truth area on all class
      """
      if len(pred.shape) == 4:
          pred = paddle.squeeze(pred, axis=1)
      if len(label.shape) == 4:
          label = paddle.squeeze(label, axis=1)
      if not pred.shape == label.shape:
          raise ValueError(
              "Shape of `pred` and `label should be equal, "
              "but there are {} and {}.".format(pred.shape, label.shape)
          )
      pred_area = []
      label_area = []
      intersect_area = []
      mask = label != ignore_index
  
      for i in range(num_classes):
          pred_i = paddle.logical_and(pred == i, mask)
          label_i = label == i
          intersect_i = paddle.logical_and(pred_i, label_i)
          pred_area.append(paddle.sum(paddle.cast(pred_i, "int32")))
          label_area.append(paddle.sum(paddle.cast(label_i, "int32")))
          intersect_area.append(
              paddle.sum(paddle.cast(intersect_i, "int32"))
          )
  
      pred_area = paddle.concat(pred_area)
      label_area = paddle.concat(label_area)
      intersect_area = paddle.concat(intersect_area)
  
      return intersect_area, pred_area, label_area
  
file_path: PaddleSeg/contrib/MedicalSeg/medicalseg/utils/metric.py
imports: import numpy
  import paddle
  import paddle.nn.functional
  import sklearn.metrics
label_desc: Use image node_id 1 for calling a global function with example usage: calculate_area(pred, label, num_classes, ignore_index) and returns: intersect_area,  pred_area,  label_area