forked from mlcommons/GaNDLF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgandlf_run
110 lines (98 loc) · 3.25 KB
/
gandlf_run
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import os, argparse, ast, sys
from GANDLF import version
from GANDLF.cli import main_run, copyrightMessage
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="GANDLF",
formatter_class=argparse.RawTextHelpFormatter,
description="Semantic segmentation, regression, and classification for medical images using Deep Learning.\n\n"
+ copyrightMessage,
)
parser.add_argument(
"-c",
"--config",
metavar="",
type=str,
help="The configuration file (contains all the information related to the training/inference session)",
)
parser.add_argument(
"-i",
"--inputdata",
metavar="",
type=str,
help="Data CSV file that is used for training/inference; can also take comma-separated training-validation pre-split CSVs",
)
parser.add_argument(
"-t",
"--train",
metavar="",
type=ast.literal_eval,
help="True: training and False: inference; for inference, there needs to be a compatible model saved in '-output'",
)
parser.add_argument(
"-m",
"--modeldir",
metavar="",
type=str,
help="Training: Output directory to save intermediate files and model weights; inference: location of previous training session output",
)
parser.add_argument(
"-d",
"--device",
default="cuda",
metavar="",
type=str,
help="Device to perform requested session on 'cpu' or 'cuda'; for cuda, ensure CUDA_VISIBLE_DEVICES env var is set",
)
parser.add_argument(
"-rt",
"--reset",
metavar="",
default=False,
type=ast.literal_eval,
help="Completely resets the previous run by deleting 'modeldir'",
)
parser.add_argument(
"-rm",
"--resume",
metavar="",
default=False,
type=ast.literal_eval,
help="Resume previous training by only keeping model dict in 'modeldir'",
)
parser.add_argument(
"-v",
"--version",
action="version",
version="%(prog)s v{}".format(version) + "\n\n" + copyrightMessage,
help="Show program's version number and exit.",
)
args = parser.parse_args()
# check for required parameters - this is needed here to keep the cli clean
for param_none_check in [args.inputdata, args.modeldir, args.train, args.config]:
if param_none_check is None:
sys.exit("ERROR: Missing required parameter:", param_none_check)
if not args.train:
# if inference mode, then no need to check for reset/resume
args.reset, args.resume = False, False
if args.reset and args.resume:
print(
"WARNING: 'reset' and 'resume' are mutually exclusive; 'resume' will be used."
)
args.reset = False
# config file should always be present
if not (os.path.isfile(args.config)):
sys.exit("ERROR: Configuration file not found!")
main_run(
args.inputdata,
args.config,
args.modeldir,
args.train,
args.device,
args.resume,
args.reset,
)
print("Finished.")