-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_search.py
41 lines (30 loc) · 1.56 KB
/
grid_search.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
import os
import subprocess
import utils.project_functions as pf
from tqdm import tqdm
root_path = os.path.dirname(os.path.abspath(__file__))
data_folder = os.path.join(root_path, 'data')
config_folder = os.path.join(root_path, 'config_files')
grid_configs_path = os.path.join(config_folder , 'grid_configs.yml')
current_config_file_path = os.path.join(config_folder , 'CurrentTest.yml')
metrics_file = os.path.join(data_folder, 'grid_search_metrics.csv')
current_training_output = os.path.join(data_folder, 'current_training_output.txt')
config_combinations, models_to_test = pf.get_configuration_combinations(grid_configs_path)
total_configs = len(config_combinations)
print('Número de configurações: ', total_configs)
input('Pressione \'Enter\' para continuar...\n')
pf.delete_old_grid_data(root_path)
best_metrics = {model: float('-inf') for model in models_to_test}
for config, ID in tqdm(zip(config_combinations, range(len(config_combinations))), total = total_configs):
config['testID'] = 'GridTest_' + str(ID)
pf.save_config(config, current_config_file_path)
with open(current_training_output, 'w+') as output_file:
subprocess.run(["python3", "model_training.py"],
check=True,
stdout=output_file)
best_metrics = pf.update_best_results(metrics_file,
best_metrics,
config,
config_folder,
monitor = 'val_SDR',
mode = 'max')