forked from artix41/ALFI-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-experiments.py
65 lines (51 loc) · 2.31 KB
/
run-experiments.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
63
64
65
import numpy as np
import yaml
import argparse
import glob
import os
import shutil
from experiment import experiment
# ================== Arguments ==================
parser = argparse.ArgumentParser(
description='Run all experiments described in the different config files'
)
parser.add_argument('configs_dir', type=str, help='Path to configs directory or to a config file')
parser.add_argument('output_dir', type=str, help='Path to the output directory')
parser.add_argument('-l', '--load', action="store_true", help='Load the last model for already existing experiments')
parser.add_argument('-v', choices=['0','1','2','3'], default=3, dest='verbose',
help='Level of verbosity, between 0 and 3')
args = parser.parse_args()
output_dir = os.path.abspath(args.output_dir)
configs_dir = os.path.abspath(args.configs_dir)
verbose = args.verbose
load = args.load
# ================ Load config files =============
if os.path.isdir(configs_dir):
config_files = glob.glob(os.path.join(configs_dir, '*.yaml'))
else:
config_files = [configs_dir]
experiment_names = [os.path.splitext(os.path.basename(f))[0] for f in config_files]
def load_config(path):
with open(path, 'r') as f:
config = yaml.load(f)
return config
for i_exp in range(len(config_files)):
exp_name = experiment_names[i_exp]
verbose = int(verbose)
if verbose >= 1:
print("\n===========================================================")
print("============== Running Experiment {:02d}: {} ==============".format(i_exp, exp_name))
print("===========================================================\n")
print("[*] Loading config files and creating output directories...\n")
config = load_config(config_files[i_exp])
exp_output_dir = os.path.join(output_dir, exp_name)
if not os.path.exists(exp_output_dir) or (os.path.exists(exp_output_dir) and not load):
if os.path.exists(exp_output_dir) and not load:
shutil.rmtree(exp_output_dir)
os.makedirs(exp_output_dir)
shutil.copy(config_files[i_exp], exp_output_dir)
if verbose >= 1:
print("[*] Starting experiment...\n")
experiment(config, exp_output_dir, load=load, verbose=verbose)
if verbose >= 1:
print("\n=================== Done ===================\n")