|
a |
|
b/run_exp_3.py |
|
|
1 |
import os |
|
|
2 |
import sys |
|
|
3 |
from run import run, run_deepecg |
|
|
4 |
|
|
|
5 |
def run_experiment3(data_path): |
|
|
6 |
''' |
|
|
7 |
Runs experiments for each lead separately for signal: |
|
|
8 |
- preprocessed as described in DeepECG and |
|
|
9 |
- with simplified preprocessing. |
|
|
10 |
|
|
|
11 |
Saves the results to a text file in the 'exp3_results' directory. |
|
|
12 |
|
|
|
13 |
Parameters: |
|
|
14 |
- data_path (str): path to the directory containing preprocessed ECG data and patient IDs |
|
|
15 |
|
|
|
16 |
Saves: |
|
|
17 |
- the lead number, accuracy, training time, and evaluation time for each lead |
|
|
18 |
''' |
|
|
19 |
|
|
|
20 |
results_deep = [] |
|
|
21 |
results_simplified = [] |
|
|
22 |
os.makedirs('exp3_results', exist_ok=True) |
|
|
23 |
|
|
|
24 |
leads = ['V3', 'III', 'V5'] |
|
|
25 |
|
|
|
26 |
for i, lead in enumerate(leads): |
|
|
27 |
|
|
|
28 |
print(f'DeepECG prepreprocessing for lead {lead}') |
|
|
29 |
accuracy, train_time, eval_time = run_deepecg(NUM_BATCH=16, |
|
|
30 |
LEAD=i, |
|
|
31 |
NUM_EPOCHS=200, |
|
|
32 |
DATA_PATH=data_path, |
|
|
33 |
FS=128) |
|
|
34 |
|
|
|
35 |
results_deep.append((lead, accuracy, train_time, eval_time)) |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
print(f'Simplified prepreprocessing for lead {lead}') |
|
|
39 |
accuracy, train_time, eval_time = run(NUM_SEGMENTS=250, |
|
|
40 |
NUM_SECONDS=10, |
|
|
41 |
NUM_BATCH=16, |
|
|
42 |
LEADS=[i], |
|
|
43 |
NUM_EPOCHS=200, |
|
|
44 |
DATA_PATH = data_path, |
|
|
45 |
FS=128) |
|
|
46 |
results_simplified.append((lead, accuracy, train_time, eval_time)) |
|
|
47 |
|
|
|
48 |
with open('exp3_results/experiment3_deep.txt', 'w') as f: |
|
|
49 |
for lead, accuracy, train_time, eval_time in results_deep: |
|
|
50 |
f.write(f"Lead: {lead}, Accuracy: {accuracy}, Training Time: {train_time}s, Evaluation Time: {eval_time}s\n") |
|
|
51 |
|
|
|
52 |
with open('exp3_results/experiment3_simple.txt', 'w') as f: |
|
|
53 |
for lead, accuracy, train_time, eval_time in results_simplified: |
|
|
54 |
f.write(f"Lead: {lead}, Accuracy: {accuracy}, Training Time: {train_time}s, Evaluation Time: {eval_time}s\n") |
|
|
55 |
|
|
|
56 |
if __name__ == "__main__": |
|
|
57 |
if len(sys.argv) != 2: |
|
|
58 |
print("Usage: python run_exp_3.py <data_path>") |
|
|
59 |
sys.exit(1) |
|
|
60 |
|
|
|
61 |
data_path = sys.argv[1] |
|
|
62 |
|
|
|
63 |
run_experiment3(data_path=data_path) |