summaryrefslogtreecommitdiff
path: root/cli/app/search/params.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-01-07 16:51:38 +0100
committerJules Laplace <julescarbon@gmail.com>2020-01-07 16:51:38 +0100
commit151ade996065ad02c2d96b723c94589066491d54 (patch)
treeb89377beed63d343ba44a833ade7c483a2b8d78c /cli/app/search/params.py
parent7ea77a044ca9de9d8089bf382640fb4a7bfabc0f (diff)
upload bytesio object to cortex
Diffstat (limited to 'cli/app/search/params.py')
-rw-r--r--cli/app/search/params.py56
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)