class_docstr: The PPMattinh implementation based on PaddlePaddle.
  
  The original article refers to
  Guowei Chen, et, al. "PP-Matting: High-Accuracy Natural Image Matting"
  (https://arxiv.org/pdf/2204.09433.pdf).
  
  Args:
      backbone: backbone model.
      pretrained(str, optional): The path of pretrianed model. Defautl: None.
class_docstr_tok: ["The","PPMattinh","implementation","based","on","PaddlePaddle",".","The","original","article","refers","to","Guowei","Chen",",","et",",","al",".","``","PP-Matting",":","High-Accuracy","Natural","Image","Matting","''","(","https",":","\/\/arxiv.org\/pdf\/2204.09433.pdf",")",".","Args",":","backbone",":","backbone","model",".","pretrained","(","str",",","optional",")",":","The","path","of","pretrianed","model",".","Defautl",":","None","."]
code: def loss(self, logit_dict, label_dict):
      loss = {}
  
      # semantic loss computation
      # get semantic label
      semantic_label = label_dict["trimap"]
      semantic_label_trans = (semantic_label == 128).astype("int64")
      semantic_label_bg = (semantic_label == 0).astype("int64")
      semantic_label = semantic_label_trans + semantic_label_bg * 2
      loss_semantic = self.loss_func_dict["semantic"][0](
          paddle.log(logit_dict["semantic"] + 1e-6),
          semantic_label.squeeze(1),
      )
      loss["semantic"] = loss_semantic
  
      # detail loss computation
      transparent = label_dict["trimap"] == 128
      detail_alpha_loss = self.loss_func_dict["detail"][0](
          logit_dict["detail"], label_dict["alpha"], transparent
      )
      # gradient loss
      detail_gradient_loss = self.loss_func_dict["detail"][1](
          logit_dict["detail"], label_dict["alpha"], transparent
      )
      loss_detail = detail_alpha_loss + detail_gradient_loss
      loss["detail"] = loss_detail
      loss["detail_alpha"] = detail_alpha_loss
      loss["detail_gradient"] = detail_gradient_loss
  
      # fusion loss
      loss_fusion_func = self.loss_func_dict["fusion"]
      # fusion_sigmoid loss
      fusion_alpha_loss = loss_fusion_func[0](
          logit_dict["fusion"], label_dict["alpha"]
      )
      # composion loss
      comp_pred = (
          logit_dict["fusion"] * label_dict["fg"]
          + (1 - logit_dict["fusion"]) * label_dict["bg"]
      )
      comp_gt = (
          label_dict["alpha"] * label_dict["fg"]
          + (1 - label_dict["alpha"]) * label_dict["bg"]
      )
      fusion_composition_loss = loss_fusion_func[1](comp_pred, comp_gt)
      # grandient loss
      fusion_grad_loss = loss_fusion_func[2](
          logit_dict["fusion"], label_dict["alpha"]
      )
      # fusion loss
      loss_fusion = (
          fusion_alpha_loss + fusion_composition_loss + fusion_grad_loss
      )
      loss["fusion"] = loss_fusion
      loss["fusion_alpha"] = fusion_alpha_loss
      loss["fusion_composition"] = fusion_composition_loss
      loss["fusion_gradient"] = fusion_grad_loss
  
      loss["all"] = (
          0.25 * loss_semantic + 0.25 * loss_detail + 0.25 * loss_fusion
      )
  
      return loss
  
imports: from collections import defaultdict
  import time
  import paddle
  import paddle.nn
  import paddle.nn.functional
  import paddleseg
  from paddleseg.models import layers
  from paddleseg import utils
  from paddleseg.cvlibs import manager
  from ppmatting.models.losses import MRSD, GradientLoss
  from ppmatting.models.backbone import resnet_vd
label_desc: Use image node_id 4 for calling the PPMatting obj's underlying member method code with example usage: obj.loss(logit_dict, label_dict) and returns: loss