-
Notifications
You must be signed in to change notification settings - Fork 19
/
yaml_parser.py
34 lines (28 loc) · 1.11 KB
/
yaml_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from ruamel.yaml import YAML
class YamlParser:
"""The YamlParser parses a yaml file containing parameters for the environment, model, evaulation, and trainer.
The data is parsed during initialization.
Retrieve the parameters using the get_config function.
The data can be accessed like:
parser.get_config()["environment"]["name"]
"""
def __init__(self, path):
"""Loads and prepares the specified config file.
Arguments:
path {str} -- Yaml file path to the to be loaded config file.
"""
# Load the config file
stream = open(path, "r")
yaml = YAML()
yaml_args = yaml.load_all(stream)
# Final contents of the config file will be added to a dictionary
self._config = {}
# Prepare data
for data in yaml_args:
self._config = dict(data)
def get_config(self):
"""
Returns:
{dict} -- Nested dictionary that contains configs for the environment, model, evaluation and trainer.
"""
return self._config