class_docstr: The DIM implementation based on PaddlePaddle.
  
  The original article refers to
  Ning Xu, et, al. "Deep Image Matting"
  (https://arxiv.org/pdf/1908.07919.pdf).
  
  Args:
      backbone: backbone model.
      stage (int, optional): The stage of model. Defautl: 3.
      decoder_input_channels(int, optional): The channel of decoder input. Default: 512.
      pretrained(str, optional): The path of pretrianed model. Defautl: None.
class_docstr_tok: ["The","DIM","implementation","based","on","PaddlePaddle",".","The","original","article","refers","to","Ning","Xu",",","et",",","al",".","``","Deep","Image","Matting","''","(","https",":","\/\/arxiv.org\/pdf\/1908.07919.pdf",")",".","Args",":","backbone",":","backbone","model",".","stage","(","int",",","optional",")",":","The","stage","of","model",".","Defautl",":","3.","decoder_input_channels","(","int",",","optional",")",":","The","channel","of","decoder","input",".","Default",":","512.","pretrained","(","str",",","optional",")",":","The","path","of","pretrianed","model",".","Defautl",":","None","."]
code: def loss(self, logit_dict, label_dict, loss_func_dict=None):
      if loss_func_dict is None:
          if self.loss_func_dict is None:
              self.loss_func_dict = defaultdict(list)
              self.loss_func_dict["alpha_raw"].append(MRSD())
              self.loss_func_dict["comp"].append(MRSD())
              self.loss_func_dict["alpha_pred"].append(MRSD())
      else:
          self.loss_func_dict = loss_func_dict
  
      loss = {}
      mask = label_dict["trimap"] == 128
      loss["all"] = 0
  
      if self.stage != 2:
          loss["alpha_raw"] = self.loss_func_dict["alpha_raw"][0](
              logit_dict["alpha_raw"], label_dict["alpha"], mask
          )
          loss["alpha_raw"] = 0.5 * loss["alpha_raw"]
          loss["all"] = loss["all"] + loss["alpha_raw"]
  
      if self.stage == 1 or self.stage == 3:
          comp_pred = (
              logit_dict["alpha_raw"] * label_dict["fg"]
              + (1 - logit_dict["alpha_raw"]) * label_dict["bg"]
          )
          loss["comp"] = self.loss_func_dict["comp"][0](
              comp_pred, label_dict["img"], mask
          )
          loss["comp"] = 0.5 * loss["comp"]
          loss["all"] = loss["all"] + loss["comp"]
  
      if self.stage == 2 or self.stage == 3:
          loss["alpha_pred"] = self.loss_func_dict["alpha_pred"][0](
              logit_dict["alpha_pred"], label_dict["alpha"], mask
          )
          loss["all"] = loss["all"] + loss["alpha_pred"]
  
      return loss
  
imports: from collections import defaultdict
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.models import layers
  from paddleseg import utils
  from paddleseg.cvlibs import manager
  from ppmatting.models.losses import MRSD
label_desc: Use image node_id 3 for calling the DIM obj's underlying member method code with example usage: obj.loss(logit_dict, label_dict, loss_func_dict) and returns: loss