-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_eval.py
51 lines (41 loc) · 1.48 KB
/
train_eval.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
import os
import argparse
import pathlib
import subprocess
data_dir = 'data'
models_dir = 'models'
output_modes = ['classification', 'regression']
architectures = ['shallow', 'deep']
def create_dir(dir_name):
try:
os.makedirs(dir_name)
except FileExistsError:
# directory already exists
pass
def train_eval(train_only, eval_only):
if not eval_only:
print('Training models...')
for dataset in pathlib.Path(data_dir).iterdir():
for o in output_modes:
for a in architectures:
subprocess.run([
'python', 'train.py',
'-d', str(dataset),
'-a', a,
'-o', o
])
if not train_only:
print('Evaluating models...')
create_dir('eval')
file = open(os.path.join('eval', 'results.csv'), 'w')
file.write('Dataset,Model Architecture,Model Type,BPM Range,MSE,MAE,Accuracy1,Accuracy2\n')
file.close()
for model_path in pathlib.Path(models_dir).iterdir():
if model_path.stem.split('.')[-1] == 'best':
subprocess.run(['python', 'evaluate.py', str(model_path), '-w'])
print('Done.')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--train-only', action='store_true')
parser.add_argument('-e', '--evaluate-only', action='store_true')
args = parser.parse_args()