class_docstr: Pass in a dataset that conforms to the format.
      matting_dataset/
      |--bg/
      |
      |--train/
      |  |--fg/
      |  |--alpha/
      |
      |--val/
      |  |--fg/
      |  |--alpha/
      |  |--trimap/ (if existing)
      |
      |--train.txt
      |
      |--val.txt
  See README.md for more information of dataset.
  
  Args:
      dataset_root(str): The root path of dataset.
      transforms(list):  Transforms for image.
      mode (str, optional): which part of dataset to use. it is one of ('train', 'val', 'trainval'). Default: 'train'.
      train_file (str|list, optional): File list is used to train. It should be `foreground_image.png background_image.png`
          or `foreground_image.png`. It shold be provided if mode equal to 'train'. Default: None.
      val_file (str|list, optional): File list is used to evaluation. It should be `foreground_image.png background_image.png`
          or `foreground_image.png` or ``foreground_image.png background_image.png trimap_image.png`.
          It shold be provided if mode equal to 'val'. Default: None.
      get_trimap (bool, optional): Whether to get triamp. Default: True.
      separator (str, optional): The separator of train_file or val_file. If file name contains ' ', '|' may be perfect. Default: ' '.
      key_del (tuple|list, optional): The key which is not need will be delete to accellect data reader. Default: None.
      if_rssn (bool, optional): Whether to use RSSN while Compositing image. Including denoise and blur. Default: False.
class_docstr_tok: ["Pass","in","a","dataset","that","conforms","to","the","format",".","matting_dataset\/","|","--","bg\/","|","|","--","train\/","|","|","--","fg\/","|","|","--","alpha\/","|","|","--","val\/","|","|","--","fg\/","|","|","--","alpha\/","|","|","--","trimap\/","(","if","existing",")","|","|","--","train.txt","|","|","--","val.txt","See","README.md","for","more","information","of","dataset",".","Args",":","dataset_root","(","str",")",":","The","root","path","of","dataset",".","transforms","(","list",")",":","Transforms","for","image",".","mode","(","str",",","optional",")",":","which","part","of","dataset","to","use",".","it","is","one","of","(","'train","'",",","'val","'",",","'trainval","'",")",".","Default",":","'train","'",".","train_file","(","str|list",",","optional",")",":","File","list","is","used","to","train",".","It","should","be","`","foreground_image.png","background_image.png","`","or","`","foreground_image.png","`",".","It","shold","be","provided","if","mode","equal","to","'train","'",".","Default",":","None",".","val_file","(","str|list",",","optional",")",":","File","list","is","used","to","evaluation",".","It","should","be","`","foreground_image.png","background_image.png","`","or","`","foreground_image.png","`","or","``","foreground_image.png","background_image.png","trimap_image.png","`",".","It","shold","be","provided","if","mode","equal","to","'val","'",".","Default",":","None",".","get_trimap","(","bool",",","optional",")",":","Whether","to","get","triamp",".","Default",":","True",".","separator","(","str",",","optional",")",":","The","separator","of","train_file","or","val_file",".","If","file","name","contains","'","'",",","'|","'","may","be","perfect",".","Default",":","'","'",".","key_del","(","tuple|list",",","optional",")",":","The","key","which","is","not","need","will","be","delete","to","accellect","data","reader",".","Default",":","None",".","if_rssn","(","bool",",","optional",")",":","Whether","to","use","RSSN","while","Compositing","image",".","Including","denoise","and","blur",".","Default",":","False","."]
code: def __getitem__(self, idx):
      data = {}
      fg_bg_file = self.fg_bg_list[idx]
      fg_bg_file = fg_bg_file.split(self.separator)
      data["img_name"] = fg_bg_file[
          0
      ]  # using in save prediction results
      fg_file = os.path.join(self.dataset_root, fg_bg_file[0])
      alpha_file = fg_file.replace("/fg", "/alpha")
      fg = cv2.imread(fg_file)
      alpha = cv2.imread(alpha_file, 0)
      data["alpha"] = alpha
      data["gt_fields"] = []
  
      # line is: fg [bg] [trimap]
      if len(fg_bg_file) >= 2:
          bg_file = os.path.join(self.dataset_root, fg_bg_file[1])
          bg = cv2.imread(bg_file)
          data["img"], data["fg"], data["bg"] = self.composite(
              fg, alpha, bg
          )
          if self.mode in ["train", "trainval"]:
              data["gt_fields"].append("fg")
              data["gt_fields"].append("bg")
              data["gt_fields"].append("alpha")
          if len(fg_bg_file) == 3 and self.get_trimap:
              if self.mode == "val":
                  trimap_path = os.path.join(
                      self.dataset_root, fg_bg_file[2]
                  )
                  if os.path.exists(trimap_path):
                      data["trimap"] = trimap_path
                      data["gt_fields"].append("trimap")
                      data["ori_trimap"] = cv2.imread(trimap_path, 0)
                  else:
                      raise FileNotFoundError(
                          "trimap is not Found: {}".format(
                              fg_bg_file[2]
                          )
                      )
      else:
          data["img"] = fg
          if self.mode in ["train", "trainval"]:
              data["fg"] = fg.copy()
              data["bg"] = fg.copy()
              data["gt_fields"].append("fg")
              data["gt_fields"].append("bg")
              data["gt_fields"].append("alpha")
  
      data["trans_info"] = []  # Record shape change information
  
      # Generate trimap from alpha if no trimap file provided
      if self.get_trimap:
          if "trimap" not in data:
              data["trimap"] = self.gen_trimap(
                  data["alpha"], mode=self.mode
              ).astype("float32")
              data["gt_fields"].append("trimap")
              if self.mode == "val":
                  data["ori_trimap"] = data["trimap"].copy()
  
      # Delete key which is not need
      if self.key_del is not None:
          for key in self.key_del:
              if key in data.keys():
                  data.pop(key)
              if key in data["gt_fields"]:
                  data["gt_fields"].remove(key)
      data = self.transforms(data)
  
      # When evaluation, gt should not be transforms.
      if self.mode == "val":
          data["gt_fields"].append("alpha")
  
      data["img"] = data["img"].astype("float32")
      for key in data.get("gt_fields", []):
          data[key] = data[key].astype("float32")
  
      if "trimap" in data:
          data["trimap"] = data["trimap"][np.newaxis, :, :]
      if "ori_trimap" in data:
          data["ori_trimap"] = data["ori_trimap"][np.newaxis, :, :]
  
      data["alpha"] = data["alpha"][np.newaxis, :, :] / 255.0
  
      return data
  
file_path: PaddleSeg/Matting/ppmatting/datasets/matting_dataset.py
imports: import os
  import math
  import cv2
  import numpy
  import random
  import paddle
  from paddleseg.cvlibs import manager
  import ppmatting.transforms
label_desc: Use image node_id 2 for calling the MattingDataset obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: data