code: def load_pretrained_model(model, pretrained_model):
      if pretrained_model is not None:
          logger.info(
              "Loading pretrained model from {}".format(
                  pretrained_model
              )
          )
  
          if urlparse(pretrained_model).netloc:
              pretrained_model = download_pretrained_model(
                  pretrained_model
              )
  
          if os.path.exists(pretrained_model):
              para_state_dict = paddle.load(pretrained_model)
  
              model_state_dict = model.state_dict()
              keys = model_state_dict.keys()
              num_params_loaded = 0
              for k in keys:
                  if k not in para_state_dict:
                      logger.warning(
                          "{} is not in pretrained model".format(k)
                      )
                  elif list(para_state_dict[k].shape) != list(
                      model_state_dict[k].shape
                  ):
                      # When the input is more than 3 channels such as trimap-based method, padding zeros to load.
                      para_shape = list(para_state_dict[k].shape)
                      model_shape = list(model_state_dict[k].shape)
                      if (
                          "weight" in k
                          and len(para_shape) > 3
                          and len(para_shape) > 3
                          and para_shape[1] < model_shape[1]
                          and para_shape[0] == model_shape[0]
                          and para_shape[2] == model_shape[2]
                          and para_shape[3] == model_shape[3]
                      ):
                          zeros_pad = paddle.zeros(
                              (
                                  para_shape[0],
                                  model_shape[1] - para_shape[1],
                                  para_shape[2],
                                  para_shape[3],
                              )
                          )
                          para_state_dict[k] = paddle.concat(
                              [para_state_dict[k], zeros_pad], axis=1
                          )
                          model_state_dict[k] = para_state_dict[k]
                          num_params_loaded += 1
                      else:
                          logger.warning(
                              "[SKIP] Shape of pretrained params {} doesn't match.(Pretrained: {}, Actual: {})".format(
                                  k,
                                  para_state_dict[k].shape,
                                  model_state_dict[k].shape,
                              )
                          )
                  else:
                      model_state_dict[k] = para_state_dict[k]
                      num_params_loaded += 1
              model.set_dict(model_state_dict)
              logger.info(
                  "There are {}/{} variables loaded into {}.".format(
                      num_params_loaded,
                      len(model_state_dict),
                      model.__class__.__name__,
                  )
              )
  
          else:
              raise ValueError(
                  "The pretrained model directory is not Found: {}".format(
                      pretrained_model
                  )
              )
      else:
          logger.info(
              "No pretrained model to load, {} will be trained from scratch.".format(
                  model.__class__.__name__
              )
          )
  
file_path: PaddleSeg/Matting/ppmatting/utils/utils.py
imports: import os
  import paddle
  from urllib.parse import urlparse
  from paddleseg.utils import logger, download_pretrained_model
label_desc: Use image node_id 4 for calling a global function with example usage: load_pretrained_model(model, pretrained_model) without return types