Modified main file to conform to messaging principle
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -21,6 +21,7 @@ Functions:
|
|||||||
main(...): provides command line interface
|
main(...): provides command line interface
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from twomartens.masterthesis import cli
|
from twomartens.masterthesis import cli
|
||||||
|
|
||||||
@ -33,45 +34,59 @@ def main() -> None:
|
|||||||
description="Train, test, and use SSD with novelty detection.",
|
description="Train, test, and use SSD with novelty detection.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_build_general(parser)
|
||||||
|
sub_parsers = _build_sub_parsers(parser)
|
||||||
|
|
||||||
|
_build_config(sub_parsers[0])
|
||||||
|
_build_prepare(sub_parsers[1])
|
||||||
|
_build_train(sub_parsers[2])
|
||||||
|
_build_test(sub_parsers[3])
|
||||||
|
_build_evaluate(sub_parsers[4])
|
||||||
|
_build_visualise(sub_parsers[5])
|
||||||
|
_build_measure(sub_parsers[6])
|
||||||
|
args = _get_user_input(parser)
|
||||||
|
action = _get_action(args.component)
|
||||||
|
_execute_action(action, args)
|
||||||
|
|
||||||
|
|
||||||
|
def _build_general(parser: argparse.ArgumentParser) -> None:
|
||||||
parser.add_argument("--verbose", action="store_true", help="provide to get extra output")
|
parser.add_argument("--verbose", action="store_true", help="provide to get extra output")
|
||||||
parser.add_argument("--debug", action="store_true", help="activate debug functionality")
|
parser.add_argument("--debug", action="store_true", help="activate debug functionality")
|
||||||
parser.add_argument('--version', action='version', version='2martens Masterthesis 0.1.0')
|
parser.add_argument('--version', action='version', version='2martens Masterthesis 0.1.0')
|
||||||
|
|
||||||
|
|
||||||
|
def _build_sub_parsers(parser: argparse.ArgumentParser) -> List[argparse.ArgumentParser]:
|
||||||
sub_parsers = parser.add_subparsers(dest="component")
|
sub_parsers = parser.add_subparsers(dest="component")
|
||||||
sub_parsers.required = True
|
sub_parsers.required = True
|
||||||
|
|
||||||
config_parser = sub_parsers.add_parser("config", help="Get and set config values")
|
config_parser = sub_parsers.add_parser("config", help="Get and set config values")
|
||||||
prepare_parser = sub_parsers.add_parser("prepare", help="Prepare SceneNet RGB-D ground truth")
|
prepare_parser = sub_parsers.add_parser("prepare", help="Prepare SceneNet RGB-D ground truth")
|
||||||
train_parser = sub_parsers.add_parser("train", help="Train a network")
|
train_parser = sub_parsers.add_parser("train", help="Train a network")
|
||||||
evaluate_parser = sub_parsers.add_parser("evaluate", help="Evaluate a network")
|
|
||||||
test_parser = sub_parsers.add_parser("test", help="Test a network")
|
test_parser = sub_parsers.add_parser("test", help="Test a network")
|
||||||
|
evaluate_parser = sub_parsers.add_parser("evaluate", help="Evaluate a network")
|
||||||
visualise_parser = sub_parsers.add_parser("visualise", help="Visualise the ground truth")
|
visualise_parser = sub_parsers.add_parser("visualise", help="Visualise the ground truth")
|
||||||
measure_parser = sub_parsers.add_parser("measure_mapping", help="Measure the number of instances per COCO category")
|
measure_parser = sub_parsers.add_parser("measure_mapping", help="Measure the number of instances per COCO category")
|
||||||
|
|
||||||
# build sub parsers
|
return [
|
||||||
_build_config(config_parser)
|
config_parser,
|
||||||
_build_prepare(prepare_parser)
|
prepare_parser,
|
||||||
_build_train(train_parser)
|
train_parser,
|
||||||
_build_test(test_parser)
|
test_parser,
|
||||||
_build_evaluate(evaluate_parser)
|
evaluate_parser,
|
||||||
_build_visualise(visualise_parser)
|
visualise_parser,
|
||||||
_build_measure(measure_parser)
|
measure_parser
|
||||||
|
]
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if args.component == "config":
|
def _get_user_input(parser: argparse.ArgumentParser) -> argparse.Namespace:
|
||||||
cli.config(args)
|
return parser.parse_args()
|
||||||
elif args.component == "prepare":
|
|
||||||
cli.prepare(args)
|
|
||||||
elif args.component == "train":
|
def _get_action(component: str) -> callable:
|
||||||
cli.train(args)
|
return getattr(cli, component)
|
||||||
elif args.component == "evaluate":
|
|
||||||
cli.evaluate(args)
|
|
||||||
elif args.component == "test":
|
def _execute_action(action: callable, input: argparse.Namespace) -> None:
|
||||||
cli.test(args)
|
action(input)
|
||||||
elif args.component == "visualise":
|
|
||||||
cli.visualise(args)
|
|
||||||
elif args.component == "measure_mapping":
|
|
||||||
cli.measure_mapping(args)
|
|
||||||
|
|
||||||
|
|
||||||
def _build_config(parser: argparse.ArgumentParser) -> None:
|
def _build_config(parser: argparse.ArgumentParser) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user