code: def calculate_area(
      pred, label, num_classes, ignore_index=255, use_multilabel=False
  ):
      """
      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.
          use_multilabel (bool, optional): Whether to enable multilabel mode. Default: False.
  
      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 not use_multilabel:
          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, "int64")))
              label_area.append(
                  paddle.sum(paddle.cast(label_i, "int64"))
              )
              intersect_area.append(
                  paddle.sum(paddle.cast(intersect_i, "int64"))
              )
  
          pred_area = paddle.stack(pred_area)
          label_area = paddle.stack(label_area)
          intersect_area = paddle.stack(intersect_area)
      else:
          pred_area = pred.sum([0, 2, 3]).astype("int64")
          label_area = label.sum([0, 2, 3]).astype("int64")
          intersect_area = (pred * label).sum([0, 2, 3]).astype("int64")
  
      return intersect_area, pred_area, label_area
  
file_path: PaddleSeg/paddleseg/utils/metrics.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, use_multilabel) and returns: intersect_area,  pred_area,  label_area