-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
62 lines (51 loc) · 1.81 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import warnings
from interpret import ecgInterpretation
import pandas as pd
import numpy as np
import h5py
import sys, os
from keras.models import load_model
from sacred import Experiment
from sacred.observers import MongoObserver
warnings.simplefilter(action='ignore', category=FutureWarning)
warnings.simplefilter(action='ignore', category=UserWarning)
ex = Experiment("interpret")
@ex.config
#Setting the default values for sacred
def get_config():
val_traces = 'data/ecg_tracings.hdf5'
model = 'data/model.hdf5'
real = None
noise = None
sim = 100
id_ecg = 1
output_name = None
output_name_mean = None
@ex.capture
#This triggers the execute function in the ecgInterpretation class in interpret.py file
def one_execution(data, sim, id_ecg, model, real, noise, output_name, output_name_mean):
signals = data[id_ecg]
if(os.path.exists(model)):
classification_model = load_model(model, compile=False)
model_interp = ecgInterpretation(id_ecg)
result = model_interp.execute(sim, classification_model, signals, T = True, realname = real, noisename = noise,
output_name = output_name, output_name_mean = output_name_mean)
return result
else:
raise Exception("no model")
@ex.capture
#Read data and triggers all requisited executions
def execute(val_traces, sim, id_ecg, model, real, noise):
# Get data
with h5py.File(val_traces, 'r') as file:
data = np.array(file['tracings'])
if(id_ecg == 'all'):
for i in range(len(data['x'])):
print(">>> processing id", i, " <<<")
one_execution(data, sim, id_ecg = i)
else:
one_execution(data, sim)
@ex.automain
def main(_run):
warnings.filterwarnings("ignore")
return execute()