forked from mlcommons/GaNDLF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gandlf_constructCSV
66 lines (56 loc) · 1.76 KB
/
gandlf_constructCSV
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
#!usr/bin/env python
# -*- coding: utf-8 -*-
import os, argparse, sys
from datetime import date
from GANDLF.utils import writeTrainingCSV
from GANDLF.cli import copyrightMessage
def main():
parser = argparse.ArgumentParser(
prog="GANDLF_ConstructCSV",
formatter_class=argparse.RawTextHelpFormatter,
description="Generate training/inference CSV from data directory.\n\n"
+ copyrightMessage,
)
parser.add_argument(
"-i",
"--inputDir",
metavar="",
type=str,
help="Input data directory which contains images in specified format",
)
parser.add_argument(
"-c",
"--channelsID",
metavar="",
type=str,
help="Channels/modalities identifier string to check for in all files in 'input_dir'; for example: --channelsID _t1.nii.gz,_t2.nii.gz",
)
parser.add_argument(
"-l",
"--labelID",
default=None,
type=str,
help="Label/mask identifier string to check for in all files in 'input_dir'; for example: --labelID _seg.nii.gz",
)
parser.add_argument(
"-o",
"--outputFile",
metavar="",
type=str,
help="Output CSV file",
)
args = parser.parse_args()
# check for required parameters - this is needed here to keep the cli clean
for param_none_check in [
args.inputDir,
args.channelsID,
args.outputFile,
]:
if param_none_check is None:
sys.exit("ERROR: Missing required parameter:", param_none_check)
inputDir = os.path.normpath(args.inputDir)
outputFile = os.path.normpath(args.outputFile)
writeTrainingCSV(inputDir, args.channelsID, args.labelID, outputFile)
# main function
if __name__ == "__main__":
main()