parser.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import yaml
  3. from easydict import EasyDict as edict
  4. class YamlParser(edict):
  5. """
  6. This is yaml parser based on EasyDict.
  7. """
  8. def __init__(self, cfg_dict=None, config_file=None):
  9. if cfg_dict is None:
  10. cfg_dict = {}
  11. if config_file is not None:
  12. assert(os.path.isfile(config_file))
  13. with open(config_file, 'r') as fo:
  14. cfg_dict.update(yaml.load(fo.read()))
  15. super(YamlParser, self).__init__(cfg_dict)
  16. def merge_from_file(self, config_file):
  17. with open(config_file, 'r') as fo:
  18. self.update(yaml.safe_load(fo.read()))
  19. #self.update(yaml.load(fo.read()))
  20. def merge_from_dict(self, config_dict):
  21. self.update(config_dict)
  22. def get_config(config_file=None):
  23. return YamlParser(config_file=config_file)
  24. if __name__ == "__main__":
  25. cfg = YamlParser(config_file="../configs/yolov3.yaml")
  26. cfg.merge_from_file("../configs/deep_sort.yaml")
  27. import ipdb; ipdb.set_trace()