code: def compute_class_connectiveity(
      pred_conn,
      label_conn,
      pred_num_conn,
      origin_pred_num_conn,
      label_num_conn,
      pred,
      real_label_num,
      real_pred_num,
      zero,
  ):
      pred_conn = paddle.to_tensor(pred_conn)
      label_conn = paddle.to_tensor(label_conn)
      pred_conn = F.one_hot(pred_conn, origin_pred_num_conn)
      label_conn = F.one_hot(label_conn, label_num_conn)
  
      ious = paddle.zeros((real_label_num, real_pred_num))
      pair_conn_sum = paddle.to_tensor([0.0], stop_gradient=False)
  
      for i in range(1, label_num_conn):
          label_i = label_conn[:, :, i]
  
          pair_conn = paddle.to_tensor([0.0], stop_gradient=False)
          pair_conn_num = 0
  
          for j in range(1, pred_num_conn):
              if hasattr(paddle.Tensor, "contiguous"):
                  pred_j_mask = pred_conn[:, :, j].contiguous()
              else:
                  pred_j_mask = pred_conn[:, :, j]
              pred_j = pred_j_mask * pred
  
              iou = compute_iou(pred_j, label_i, zero)
              ious[i - 1, j - 1] = iou
              if iou != 0:
                  pair_conn += iou
                  pair_conn_num += 1
  
          if pair_conn_num != 0:
              pair_conn_sum += pair_conn / pair_conn_num
      lone_pred_num = 0
  
      pred_sum = paddle.sum(ious, axis=0)
      for m in range(0, real_pred_num):
          if pred_sum[m] == 0:
              lone_pred_num += 1
      img_connectivity = pair_conn_sum / (
          real_label_num + lone_pred_num
      )
      return img_connectivity
  
file_path: PaddleSeg/paddleseg/models/losses/semantic_connectivity_loss.py
imports: import cv2
  import numpy
  import paddle
  from paddle import nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
label_desc: Use image node_id 1 for calling a global function with example usage: compute_class_connectiveity(pred_conn, label_conn, pred_num_conn, origin_pred_num_conn, label_num_conn, pred, real_label_num, real_pred_num, zero) and returns: img_connectivity