|
a |
|
b/create_batch_scripts.py |
|
|
1 |
from utils.elastix import excute_cmd |
|
|
2 |
from utils.logger import logger |
|
|
3 |
from utils.filemanager import extract_parameter |
|
|
4 |
|
|
|
5 |
if __name__ == '__main__': |
|
|
6 |
# list down the parameters files to create a batch script for each |
|
|
7 |
parameters_base_path = 'elastix-parameters' |
|
|
8 |
|
|
|
9 |
single_parameters_to_script = [ |
|
|
10 |
# Par0003 |
|
|
11 |
f'{parameters_base_path}/Par0003/Par0003.affine.txt', |
|
|
12 |
f'{parameters_base_path}/Par0003/Par0003.bs-R1-fg.txt', |
|
|
13 |
f'{parameters_base_path}/Par0003/Par0003.bs-R1-ug.txt', |
|
|
14 |
f'{parameters_base_path}/Par0003/Par0003.bs-R2-fg.txt', |
|
|
15 |
f'{parameters_base_path}/Par0003/Par0003.bs-R2-ug.txt', |
|
|
16 |
f'{parameters_base_path}/Par0003/Par0003.bs-R3-fg.txt', |
|
|
17 |
f'{parameters_base_path}/Par0003/Par0003.bs-R3-ug.txt', |
|
|
18 |
f'{parameters_base_path}/Par0003/Par0003.bs-R4-fg.txt', |
|
|
19 |
f'{parameters_base_path}/Par0003/Par0003.bs-R4-ug.txt', |
|
|
20 |
f'{parameters_base_path}/Par0003/Par0003.bs-R5-fg.txt', |
|
|
21 |
f'{parameters_base_path}/Par0003/Par0003.bs-R6-fg.txt', |
|
|
22 |
f'{parameters_base_path}/Par0003/Par0003.bs-R6-ug.txt', |
|
|
23 |
f'{parameters_base_path}/Par0003/Par0003.bs-R7-fg.txt', |
|
|
24 |
f'{parameters_base_path}/Par0003/Par0003.bs-R7-ug.txt', |
|
|
25 |
f'{parameters_base_path}/Par0003/Par0003.bs-R8-fg.txt', |
|
|
26 |
f'{parameters_base_path}/Par0003/Par0003.bs-R8-ug.txt', |
|
|
27 |
|
|
|
28 |
# Par0007 |
|
|
29 |
f'{parameters_base_path}/Par0007/Parameters.MI.Coarse.Bspline_tuned.txt', |
|
|
30 |
f'{parameters_base_path}/Par0007/Parameters.MI.Fine.Bspline_tuned.txt', |
|
|
31 |
f'{parameters_base_path}/Par0007/Parameters.MI.RP.Bspline_tuned.txt', |
|
|
32 |
|
|
|
33 |
# Par0011 |
|
|
34 |
f'{parameters_base_path}/Par0011/Parameters.Par0011.affine.txt', |
|
|
35 |
f'{parameters_base_path}/Par0011/Parameters.Par0011.bspline1_s.txt', |
|
|
36 |
f'{parameters_base_path}/Par0011/Parameters.Par0011.bspline2_s.txt', |
|
|
37 |
|
|
|
38 |
# Par0049 |
|
|
39 |
f'{parameters_base_path}/Par0049/Par0049_stdT-advanced.txt', |
|
|
40 |
f'{parameters_base_path}/Par0049/Par0049_stdT2000itr.txt', |
|
|
41 |
f'{parameters_base_path}/Par0049/Par0049_stdTL-advanced.txt', |
|
|
42 |
f'{parameters_base_path}/Par0049/Par0049_stdTL.txt' |
|
|
43 |
] |
|
|
44 |
|
|
|
45 |
# create a batch script for each parameters file |
|
|
46 |
experiment_name = 'CLAHE+UseMasks3+SingleParamFile' |
|
|
47 |
dataset_path = 'dataset_processed/CLAHE/train' |
|
|
48 |
print(f"Experiment name: {experiment_name}...") |
|
|
49 |
print(f"Dataset path: {dataset_path}... \n") |
|
|
50 |
|
|
|
51 |
# create a batch script for each parameters file |
|
|
52 |
for idx, param_path in enumerate(single_parameters_to_script): |
|
|
53 |
logger.info(f"[{idx+1}/{len(single_parameters_to_script)}] Creating batch script for {param_path}.") |
|
|
54 |
|
|
|
55 |
# create the script |
|
|
56 |
command = f'python create_script.py \ |
|
|
57 |
--dataset_path "{dataset_path}" \ |
|
|
58 |
--experiment_name "{experiment_name}" \ |
|
|
59 |
--parameters_path "{param_path}" \ |
|
|
60 |
--use_masks' |
|
|
61 |
excute_cmd(command) |
|
|
62 |
|
|
|
63 |
# run the script |
|
|
64 |
# {param_path.split("/")[-1].replace(".txt", "")} was taken from create_script.py for a single command passed |
|
|
65 |
command = f'call output/{experiment_name}/{param_path.split("/")[-1].replace(".txt", "")}/elastix_transformix.bat' |
|
|
66 |
excute_cmd(command) |
|
|
67 |
|
|
|
68 |
# evaluate the script |
|
|
69 |
command = f'python evaluate_transformation.py \ |
|
|
70 |
--experiment_name "{experiment_name}" \ |
|
|
71 |
--reg_params_key "{param_path.split("/")[-1].replace(".txt", "")}" \ |
|
|
72 |
--dataset_path "{dataset_path}"\ |
|
|
73 |
--generate_report' |
|
|
74 |
excute_cmd(command) |