code: def get_bg(bg_path, shape):
      bg = paddle.zeros((1, 3, shape[0], shape[1]))
      # special color
      if bg_path == "r":
          bg[:, 2, :, :] = 1
      elif bg_path == "g":
          bg[:, 1, :, :] = 1
      elif bg_path == "b":
          bg[:, 0, :, :] = 1
      elif bg_path == "w":
          bg = bg + 1
  
      elif not os.path.exists(bg_path):
          raise Exception(
              "The background path is not found: {}".format(bg_path)
          )
      # image
      elif bg_path.endswith(
          (
              ".JPEG",
              ".jpeg",
              ".JPG",
              ".jpg",
              ".BMP",
              ".bmp",
              ".PNG",
              ".png",
          )
      ):
          bg = cv2.imread(bg_path)
          bg = bg[np.newaxis, :, :, :]
          bg = paddle.to_tensor(bg) / 255.0
          bg = bg.transpose((0, 3, 1, 2))
  
      elif bg_path.lower().endswith(
          (
              ".mp4",
              ".avi",
              ".mov",
              ".m4v",
              ".dat",
              ".rm",
              ".rmvb",
              ".wmv",
              ".asf",
              ".asx",
              ".3gp",
              ".mkv",
              ".flv",
              ".vob",
          )
      ):
          transforms = T.Compose(
              [T.Normalize(mean=(0, 0, 0), std=(1, 1, 1))]
          )
          bg = VideoReader(bg_path, transforms=transforms)
          bg = paddle.io.DataLoader(bg)
          bg = iter(bg)
  
      else:
          raise IOError(
              "The background path is invalid, please check it"
          )
  
      return bg
  
file_path: PaddleSeg/Matting/ppmatting/core/bg_replace_video.py
imports: import os
  import math
  import time
  from collections.abc import Iterable
  import cv2
  import numpy
  import paddle
  import paddle.nn.functional
  from paddleseg import utils
  from paddleseg.core import infer
  from paddleseg.utils import logger, progbar, TimeAverager
  import ppmatting.transforms
  from ppmatting.utils import mkdir, estimate_foreground_ml, VideoReader, VideoWriter
label_desc: Use image node_id 4 for calling a global function with example usage: get_bg(bg_path, shape) and returns: bg