This gist helps you to handle global variables such as hyper-parameters in your python projects.
- hyperparamsloader.py
- sample_params.yaml
- sample_params.json
- import module with
from hyperparamsloader import load_params
- prepare/edit parameters-file in YAML/JSON format (see sample_params.yaml/.json FYI)
- load parameters;
params = load_params('sample_params.yaml')
- In your code, the loaded variables can be used in this way;
params["param1"]
If you want to assign a default value to a variable,
you can set it in the load_params function.
Please add the pairs of keys and values of the variables
into parameters={}
on line 12 in hyperparamsloader.py
script.
When a variable having the same name as the one set here is brought
by a parameters-file written in YAML or JSON format,
it will be overwritten by the value in the YAML/JSON file.