From 5aee21743a0a4b79f68643c40b460465bbb82586 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 22 Mar 2021 14:59:48 +0100 Subject: [PATCH] simplify ground-truth and --show_all --- monoloco/network/process.py | 22 +++++++--------------- monoloco/predict.py | 3 +++ monoloco/run.py | 3 +-- monoloco/visuals/printer.py | 4 +--- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/monoloco/network/process.py b/monoloco/network/process.py index 23c0ba4..9d28724 100644 --- a/monoloco/network/process.py +++ b/monoloco/network/process.py @@ -66,26 +66,18 @@ def preprocess_monoloco(keypoints, kk, zero_center=False): return kps_out -def factory_for_gt(im_size, focal_length=5.7, name=None, path_gt=None, verbose=True): +def factory_for_gt(im_size, focal_length=5.7, name=None, path_gt=None): """Look for ground-truth annotations file and define calibration matrix based on image size """ - try: + if path_gt is not None: + assert os.path.exists(path_gt), "Ground-truth file not found" with open(path_gt, 'r') as f: dic_names = json.load(f) - if verbose: - logger.info('-' * 120 + "\nGround-truth file opened") - except (FileNotFoundError, TypeError): - if verbose: - logger.info('-' * 120 + "\nGround-truth file not found") - dic_names = {} + kk = dic_names[name]['K'] + dic_gt = dic_names[name] - try: - kk = dic_names[name]['K'] - dic_gt = dic_names[name] - if verbose: - logger.info("Matched ground-truth file!") - except KeyError: - dic_gt = None + # Without ground-truth-file + else: if im_size[0] / im_size[1] > 2.5: # KITTI default kk = [[718.3351, 0., 600.3891], [0., 718.3351, 181.5122], [0., 0., 1.]] # Kitti calibration logger.info("Using KITTI calibration matrix...") diff --git a/monoloco/predict.py b/monoloco/predict.py index 928d2c4..85b95dc 100644 --- a/monoloco/predict.py +++ b/monoloco/predict.py @@ -82,6 +82,9 @@ def factory_from_args(args): if not args.images: raise Exception("no image files given") + if args.path_gt is None: + args.show_all = True + # Models dic_models = download_checkpoints(args) args.checkpoint = dic_models['keypoints'] diff --git a/monoloco/run.py b/monoloco/run.py index 9d4ed3f..e7a4f9c 100644 --- a/monoloco/run.py +++ b/monoloco/run.py @@ -61,8 +61,7 @@ def cli(): predict_parser.add_argument('--mode', help='keypoints, mono, stereo', default='mono') predict_parser.add_argument('--model', help='path of MonoLoco/MonStereo model to load') predict_parser.add_argument('--net', help='only to select older MonoLoco model, otherwise use --mode') - predict_parser.add_argument('--path_gt', help='path of json file with gt 3d localization', - default='data/arrays/names-kitti-200615-1022.json') + predict_parser.add_argument('--path_gt', help='path of json file with gt 3d localization') predict_parser.add_argument('--z_max', type=int, help='maximum meters distance for predictions', default=100) predict_parser.add_argument('--n_dropout', type=int, help='Epistemic uncertainty evaluation', default=0) predict_parser.add_argument('--dropout', type=float, help='dropout parameter', default=0.2) diff --git a/monoloco/visuals/printer.py b/monoloco/visuals/printer.py index 102a838..8d5312c 100644 --- a/monoloco/visuals/printer.py +++ b/monoloco/visuals/printer.py @@ -60,7 +60,6 @@ class Printer: self.output_types = args.output_types self.z_max = args.z_max # set max distance to show instances self.show_all = args.show_all - self.show = args.show_all self.save = not args.no_save # define image attributes @@ -170,8 +169,7 @@ class Printer: # whether to include instances that don't match the ground-truth iterator = range(len(self.zz_pred)) if self.show_all else range(len(self.zz_gt)) if not iterator: - print("-" * 110 + '\n' + "! No instances detected, be sure to include file with ground-truth values or " - "use the command --show_all" + '\n' + "-" * 110) + print("-" * 110 + '\n' + '! No instances detected' '\n' + '-' * 110) # Draw the front figure number = dict(flag=False, num=97)