diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-12-08 21:43:30 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-12-08 21:43:30 +0100 |
| commit | fb70ab05768fa4a54358dc1f304b68bc7aff6dae (patch) | |
| tree | 6ba4c805ce37b5b8827b08946f0b22f639fa3e14 /inversion/params.py | |
| parent | 326db345db13b1ab3a76406644654cb78b4d1b8d (diff) | |
inversion json files
Diffstat (limited to 'inversion/params.py')
| -rw-r--r-- | inversion/params.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/inversion/params.py b/inversion/params.py new file mode 100644 index 0000000..dd9a358 --- /dev/null +++ b/inversion/params.py @@ -0,0 +1,27 @@ +# ------------------------------------------------------------------------------ +# 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__ |
