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 __init__(
      self,
      dataset_root,
      transforms,
      mode="train",
      train_file=None,
      val_file=None,
      get_trimap=True,
      separator=" ",
      key_del=None,
      if_rssn=False,
  ):
      super().__init__()
      self.dataset_root = dataset_root
      self.transforms = T.Compose(transforms)
      self.mode = mode
      self.get_trimap = get_trimap
      self.separator = separator
      self.key_del = key_del
      self.if_rssn = if_rssn
  
      # check file
      if mode == "train" or mode == "trainval":
          if train_file is None:
              raise ValueError(
                  "When `mode` is 'train' or 'trainval', `train_file must be provided!"
              )
          if isinstance(train_file, str):
              train_file = [train_file]
          file_list = train_file
  
      if mode == "val" or mode == "trainval":
          if val_file is None:
              raise ValueError(
                  "When `mode` is 'val' or 'trainval', `val_file must be provided!"
              )
          if isinstance(val_file, str):
              val_file = [val_file]
          file_list = val_file
  
      if mode == "trainval":
          file_list = train_file + val_file
  
      # read file
      self.fg_bg_list = []
      for file in file_list:
          file = os.path.join(dataset_root, file)
          with open(file, "r") as f:
              lines = f.readlines()
              for line in lines:
                  line = line.strip()
                  self.fg_bg_list.append(line)
      if mode != "val":
          random.shuffle(self.fg_bg_list)
  
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 1 to create a new MattingDataset object from inherited base classes: paddle.io with example: obj = MattingDataset(dataset_root, transforms, mode, train_file, val_file, get_trimap, separator, key_del, if_rssn)