diff options
Diffstat (limited to 'cli/app/search/params.py')
| -rw-r--r-- | cli/app/search/params.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cli/app/search/params.py b/cli/app/search/params.py new file mode 100644 index 0000000..8972436 --- /dev/null +++ b/cli/app/search/params.py @@ -0,0 +1,56 @@ +# ------------------------------------------------------------------------------ +# 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 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, json_path): + """Loads parameters from json file.""" + with open(json_path) as f: + params = json.load(f) + self.__dict__.update(params) + + @property + def dict(self): + """Gives dict-like access to Params instance.""" + return self.__dict__ + +class ParamsDict(): + """Class that loads hyperparameters from a json file.""" + + def __init__(self, data): + self.update(data) + + 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) |
