class_docstr: SCL (Semantic Connectivity-aware Learning) framework, which introduces a SC Loss (Semantic Connectivity-aware Loss)
  to improve the quality of segmentation results from the perspective of connectivity. Support multi-class segmentation.
  
  The original article refers to
      Lutao Chu, Yi Liu, Zewu Wu, Shiyu Tang, Guowei Chen, Yuying Hao, Juncai Peng, Zhiliang Yu, Zeyu Chen, Baohua Lai, Haoyi Xiong.
      "PP-HumanSeg: Connectivity-Aware Portrait Segmentation with a Large-Scale Teleconferencing Video Dataset"
      In WACV 2022 workshop
      https://arxiv.org/abs/2112.07146
  
  Running process:
  Step 1. Connected Components Calculation
  Step 2. Connected Components Matching and SC Loss Calculation
docstr: Args:
      logits (Tensor): [N, C, H, W]
      lables (Tensor): [N, H, W]
code: def forward(self, logits, labels):
      """
      Args:
          logits (Tensor): [N, C, H, W]
          lables (Tensor): [N, H, W]
      """
      preds = (
          paddle.argmax(logits, axis=1) if self.use_argmax else logits
      )
      preds_np = preds.astype("uint8").numpy()
      labels_np = labels.astype("uint8").numpy()
      preds = paddle.to_tensor(preds, "float32", stop_gradient=False)
      multi_class_sc_loss = paddle.zeros([preds.shape[0]])
      zero = paddle.to_tensor([0.0])  # for accelerating
  
      # Traverse each image
      for i in range(preds.shape[0]):
          sc_loss = 0
          class_num = 0
  
          pred_i = preds[i]
          preds_np_i = preds_np[i]
          labels_np_i = labels_np[i]
  
          # Traverse each class
          for class_ in np.unique(labels_np_i):
              if class_ == self.ignore_index:
                  continue
              class_num += 1
  
              # Connected Components Calculation
              preds_np_class = preds_np_i == class_
              labels_np_class = labels_np_i == class_
              pred_num_conn, pred_conn = cv2.connectedComponents(
                  preds_np_class.astype(np.uint8)
              )  # pred_conn.shape = [H,W]
              label_num_conn, label_conn = cv2.connectedComponents(
                  labels_np_class.astype(np.uint8)
              )
  
              origin_pred_num_conn = pred_num_conn
              if pred_num_conn > 2 * label_num_conn:
                  pred_num_conn = min(
                      pred_num_conn, self.max_pred_num_conn
                  )
              real_pred_num = pred_num_conn - 1
              real_label_num = label_num_conn - 1
  
              # Connected Components Matching and SC Loss Calculation
              if real_label_num > 0 and real_pred_num > 0:
                  img_connectivity = compute_class_connectiveity(
                      pred_conn,
                      label_conn,
                      pred_num_conn,
                      origin_pred_num_conn,
                      label_num_conn,
                      pred_i,
                      real_label_num,
                      real_pred_num,
                      zero,
                  )
                  sc_loss += 1 - img_connectivity
              elif real_label_num == 0 and real_pred_num == 0:
                  # if no connected component, SC Loss = 0, so pass
                  pass
              else:
                  preds_class = pred_i == int(class_)
                  not_preds_class = paddle.bitwise_not(preds_class)
                  labels_class = paddle.to_tensor(labels_np_class)
                  missed_detect = labels_class * not_preds_class
                  missed_detect_area = paddle.sum(missed_detect).astype(
                      "float32"
                  )
                  sc_loss += (
                      missed_detect_area / missed_detect.numel() + 1
                  )
  
          multi_class_sc_loss[i] = (
              sc_loss / class_num if class_num != 0 else 0
          )
      multi_class_sc_loss = paddle.mean(multi_class_sc_loss)
      return multi_class_sc_loss
  
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 2 for calling the SemanticConnectivityLoss obj's underlying member method code with example usage: obj.forward(logits, labels) and returns: multi_class_sc_loss