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 forward(self, inputs):
      input_shape = paddle.shape(inputs["img"])[-2:]
      x = paddle.concat([inputs["img"], inputs["trimap"] / 255], axis=1)
      fea_list = self.backbone(x)
  
      # decoder stage
      up_shape = []
      for i in range(5):
          up_shape.append(paddle.shape(fea_list[i])[-2:])
      alpha_raw = self.decoder(fea_list, up_shape)
      alpha_raw = F.interpolate(
          alpha_raw, input_shape, mode="bilinear", align_corners=False
      )
      logit_dict = {"alpha_raw": alpha_raw}
      if self.stage < 2:
          return logit_dict
  
      if self.stage >= 2:
          # refine stage
          refine_input = paddle.concat(
              [inputs["img"], alpha_raw], axis=1
          )
          alpha_refine = self.refine(refine_input)
  
          # finally alpha
          alpha_pred = alpha_refine + alpha_raw
          alpha_pred = F.interpolate(
              alpha_pred,
              input_shape,
              mode="bilinear",
              align_corners=False,
          )
          if not self.training:
              alpha_pred = paddle.clip(alpha_pred, min=0, max=1)
          logit_dict["alpha_pred"] = alpha_pred
      if self.training:
          loss_dict = self.loss(logit_dict, inputs)
          return logit_dict, loss_dict
      else:
          return alpha_pred
  
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 2 for calling the DIM obj's underlying member method code with example usage: obj.forward(inputs) and returns: logit_dict, logit_dict,  loss_dict, alpha_pred