config.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import codecs
  15. import os
  16. from typing import Any, Dict, Generic
  17. import warnings
  18. from ast import literal_eval
  19. import paddle
  20. import yaml
  21. import six
  22. import paddleseg
  23. from paddleseg.utils import logger
  24. from paddleseg.cvlibs import config_checker as checker
  25. from paddleseg.utils.utils import CachedProperty as cached_property
  26. class Config(paddleseg.cvlibs.Config):
  27. @classmethod
  28. def _build_default_checker(cls):
  29. rules = []
  30. return checker.ConfigChecker(rules, allow_update=True)
  31. class MatBuilder(paddleseg.cvlibs.SegBuilder):
  32. """
  33. This class is responsible for building components for matting.
  34. """
  35. @cached_property
  36. def model(self) -> paddle.nn.Layer:
  37. model_cfg = self.config.model_cfg
  38. assert model_cfg != {}, \
  39. 'No model specified in the configuration file.'
  40. self.show_msg('model', model_cfg)
  41. return self.build_component(model_cfg)