From 151ade996065ad02c2d96b723c94589066491d54 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 7 Jan 2020 16:51:38 +0100 Subject: upload bytesio object to cortex --- cli/app/search/params.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cli/app/search/params.py (limited to 'cli/app/search/params.py') 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) -- cgit v1.2.3-70-g09d2