-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
44 lines (29 loc) · 1001 Bytes
/
utilities.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
35
36
37
38
39
40
41
42
43
44
import json
class Hyperparameters():
def __init__(self):
self.update('hyperparameters.json')
def save(self, json_path):
"""
Save the hyperparameters to a JSON file.
Parameters:
- json_path (str): The path to the JSON file where hyperparameters will be saved.
"""
with open(json_path, 'w') as f:
json.dump(self.__dict__, f, indent=4)
def update(self, json_path):
"""
Update the hyperparameters by loading them from a JSON file.
Parameters:
- json_path (str): The path to the JSON file containing hyperparameters.
"""
with open(json_path) as f:
hyperparameters = json.load(f)
self.__dict__.update(hyperparameters)
@property
def dict(self):
"""
Get the hyperparameters as a dictionary.
Returns:
- dict: A dictionary containing the hyperparameters.
"""
return self.__dict__