Class that loads hyperparameters from a json file. Example: ``` params = Params(json_path) print(params.learning_rate) params.learning_rate = 0.5 # change the value of learning_rate in params ```
| 5 | |
| 6 | |
| 7 | class Params(): |
| 8 | """Class that loads hyperparameters from a json file. |
| 9 | |
| 10 | Example: |
| 11 | ``` |
| 12 | params = Params(json_path) |
| 13 | print(params.learning_rate) |
| 14 | params.learning_rate = 0.5 # change the value of learning_rate in params |
| 15 | ``` |
| 16 | """ |
| 17 | |
| 18 | def __init__(self, json_path): |
| 19 | self.update(json_path) |
| 20 | |
| 21 | def save(self, json_path): |
| 22 | """Saves parameters to json file""" |
| 23 | with open(json_path, 'w') as f: |
| 24 | json.dump(self.__dict__, f, indent=4) |
| 25 | |
| 26 | def update(self, json_path): |
| 27 | """Loads parameters from json file""" |
| 28 | with open(json_path) as f: |
| 29 | params = json.load(f) |
| 30 | self.__dict__.update(params) |
| 31 | |
| 32 | @property |
| 33 | def dict(self): |
| 34 | """Gives dict-like access to Params instance by `params.dict['learning_rate']`""" |
| 35 | return self.__dict__ |
| 36 | |
| 37 | |
| 38 | def set_logger(log_path): |
no outgoing calls
no test coverage detected