-
Notifications
You must be signed in to change notification settings - Fork 1
/
table_recognition.py
45 lines (36 loc) · 1.58 KB
/
table_recognition.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
import argparse
from table_recognition.config import Config
from table_recognition.data_preparation import data_preparation
from table_recognition import Trainer
def check_arguments(arg):
"""
A function that checks whether valid combination of
arguments is used.
:type arg: ArgumentParser
:param arg: Parsed arguments that should be checked.
:return: True when valid combination of arguments is used
False otherwise
"""
return not (not arg.train ^ arg.infer) ^ arg.data_preparation
if __name__ == "__main__":
parser = argparse.ArgumentParser("Table recognition")
parser.add_argument("--train",
help="Train model for table recognition (--config-file required)",
action="store_true")
parser.add_argument("--infer",
help="Use trained model for table recognition (--config-file required)",
action="store_true")
parser.add_argument("--data-preparation",
help="Prepare dataset for training (--config-file required)",
action="store_true")
parser.add_argument("--config-file",
help="Path to configuration file",
default="./config.ini")
args = parser.parse_args()
if not check_arguments(args):
raise Exception("ERROR: Either --train, --infer or --data-preparation must be specified.")
config = Config(args.config_file)
if args.data_preparation:
data_preparation(config)
elif args.train:
Trainer(config)