class_docstr: Training configuration parsing. The only yaml/yml file is supported.
  
  The following hyper-parameters are available in the config file:
      batch_size: The number of samples per gpu.
      iters: The total training steps.
      train_dataset: A training data config including type/data_root/transforms/mode.
          For data type, please refer to paddleseg.datasets.
          For specific transforms, please refer to paddleseg.transforms.transforms.
      val_dataset: A validation data config including type/data_root/transforms/mode.
      optimizer: A optimizer config, but currently PaddleSeg only supports sgd with momentum in config file.
          In addition, weight_decay could be set as a regularization.
      learning_rate: A learning rate config. If decay is configured, learning _rate value is the starting learning rate,
           where only poly decay is supported using the config file. In addition, decay power and end_lr are tuned experimentally.
      loss: A loss config. Multi-loss config is available. The loss type order is consistent with the seg model outputs,
          where the coef term indicates the weight of corresponding loss. Note that the number of coef must be the same as the number of
          model outputs, and there could be only one loss type if using the same loss type among the outputs, otherwise the number of
          loss type must be consistent with coef.
      model: A model config including type/backbone and model-dependent arguments.
          For model type, please refer to paddleseg.models.
          For backbone, please refer to paddleseg.models.backbones.
  
  Args:
      path (str) : The path of config file, supports yaml format only.
  
  Examples:
  
      from paddleseg.cvlibs.config import Config
  
      # Create a cfg object with yaml file path.
      cfg = Config(yaml_cfg_path)
  
      # Parsing the argument when its property is used.
      train_dataset = cfg.train_dataset
  
      # the argument of model should be parsed after dataset,
      # since the model builder uses some properties in dataset.
      model = cfg.model
      ...
class_docstr_tok: ["Training","configuration","parsing",".","The","only","yaml\/yml","file","is","supported",".","The","following","hyper-parameters","are","available","in","the","config","file",":","batch_size",":","The","number","of","samples","per","gpu",".","iters",":","The","total","training","steps",".","train_dataset",":","A","training","data","config","including","type\/data_root\/transforms\/mode",".","For","data","type",",","please","refer","to","paddleseg.datasets",".","For","specific","transforms",",","please","refer","to","paddleseg.transforms.transforms",".","val_dataset",":","A","validation","data","config","including","type\/data_root\/transforms\/mode",".","optimizer",":","A","optimizer","config",",","but","currently","PaddleSeg","only","supports","sgd","with","momentum","in","config","file",".","In","addition",",","weight_decay","could","be","set","as","a","regularization",".","learning_rate",":","A","learning","rate","config",".","If","decay","is","configured",",","learning","_rate","value","is","the","starting","learning","rate",",","where","only","poly","decay","is","supported","using","the","config","file",".","In","addition",",","decay","power","and","end_lr","are","tuned","experimentally",".","loss",":","A","loss","config",".","Multi-loss","config","is","available",".","The","loss","type","order","is","consistent","with","the","seg","model","outputs",",","where","the","coef","term","indicates","the","weight","of","corresponding","loss",".","Note","that","the","number","of","coef","must","be","the","same","as","the","number","of","model","outputs",",","and","there","could","be","only","one","loss","type","if","using","the","same","loss","type","among","the","outputs",",","otherwise","the","number","of","loss","type","must","be","consistent","with","coef",".","model",":","A","model","config","including","type\/backbone","and","model-dependent","arguments",".","For","model","type",",","please","refer","to","paddleseg.models",".","For","backbone",",","please","refer","to","paddleseg.models.backbones",".","Args",":","path","(","str",")",":","The","path","of","config","file",",","supports","yaml","format","only",".","Examples",":","from","paddleseg.cvlibs.config","import","Config","#","Create","a","cfg","object","with","yaml","file","path",".","cfg","=","Config","(","yaml_cfg_path",")","#","Parsing","the","argument","when","its","property","is","used",".","train_dataset","=","cfg.train_dataset","#","the","argument","of","model","should","be","parsed","after","dataset",",","#","since","the","model","builder","uses","some","properties","in","dataset",".","model","=","cfg.model","..."]
docstr: Parse the loss parameters and load the loss layers.
  
  Args:
      loss_name (str): The root name of loss in the yaml file.
  Returns:
      dict: A dict including the loss parameters and layers.
docstr_tok: ["Parse","the","loss","parameters","and","load","the","loss","layers",".","Args",":","loss_name","(","str",")",":","The","root","name","of","loss","in","the","yaml","file",".","Returns",":","dict",":","A","dict","including","the","loss","parameters","and","layers","."]
code: def _prepare_loss(self, loss_name):
      """
      Parse the loss parameters and load the loss layers.
  
      Args:
          loss_name (str): The root name of loss in the yaml file.
      Returns:
          dict: A dict including the loss parameters and layers.
      """
      args = self.dic.get(loss_name, {}).copy()
      if "types" in args and "coef" in args:
          len_types = len(args["types"])
          len_coef = len(args["coef"])
          if len_types != len_coef:
              if len_types == 1:
                  args["types"] = args["types"] * len_coef
              else:
                  raise ValueError(
                      "The length of types should equal to coef or equal to 1 in loss config, but they are {} and {}.".format(
                          len_types, len_coef
                      )
                  )
      else:
          raise ValueError(
              'Loss config should contain keys of "types" and "coef"'
          )
  
      losses = dict()
      for key, val in args.items():
          if key == "types":
              losses["types"] = []
              for item in args["types"]:
                  if item["type"] != "MixedLoss":
                      if "ignore_index" in item:
                          assert (
                              item["ignore_index"]
                              == self.train_dataset.ignore_index
                          ), (
                              "If ignore_index of loss is set, "
                              "the ignore_index of loss and train_dataset must be the same. \nCurrently, loss ignore_index = {}, "
                              "train_dataset ignore_index = {}. \nIt is recommended not to set loss ignore_index, so it is consistent with "
                              "train_dataset by default.".format(
                                  item["ignore_index"],
                                  self.train_dataset.ignore_index,
                              )
                          )
                      item[
                          "ignore_index"
                      ] = self.train_dataset.ignore_index
                  losses["types"].append(self._load_object(item))
          else:
              losses[key] = val
      if len(losses["coef"]) != len(losses["types"]):
          raise RuntimeError(
              "The length of coef should equal to types in loss config: {} != {}.".format(
                  len(losses["coef"]), len(losses["types"])
              )
          )
      return losses
  
imports: import os
  import yaml
  import paddle
  import codecs
  from typing import Any, Dict, Generic
  from paddleseg.cvlibs import manager
  from paddleseg.utils import logger
  from models import EMA
label_desc: Use image node_id 14 for calling the Config obj's underlying member method code with example usage: obj._prepare_loss(loss_name) and returns: losses