blob: 7333cb95585292a28fb710d77c97f773c9606184 (
plain)
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
|
# ------------------------------------------------------------------------------
# Util class for hyperparams.
# ------------------------------------------------------------------------------
import json
class Params():
"""Class that loads hyperparameters from a json file."""
def __init__(self, json_path):
self.update(json_path)
def __setitem__(self, key, item):
self.__dict__[key] = item
def __getitem__(self, key):
return self.__dict__[key]
def __repr__(self):
return repr(self.__dict__)
def __len__(self):
return len(self.__dict__)
def __delitem__(self, key):
del self.__dict__[key]
def save(self, json_path):
"""Saves parameters to json file."""
with open(json_path, 'w') as f:
json.dump(self.__dict__, f, indent=4)
def update(self, *args, **kwargs):
return self.__dict__.update(*args, **kwargs)
# @property
# def dict(self):
# """Gives dict-like access to Params instance."""
# return self.__dict__
|