From 83a2fb801937c70d60b47190f0333d7d31a2d0a0 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Fri, 26 Jul 2019 08:32:18 +0200 Subject: [PATCH] refactor article figures --- monoloco/eval/eval_kitti.py | 11 +++---- monoloco/run.py | 3 +- monoloco/visuals/__init__.py | 2 +- monoloco/visuals/figures.py | 60 +++++++++++++++++++----------------- monoloco/visuals/results.py | 0 5 files changed, 39 insertions(+), 37 deletions(-) delete mode 100644 monoloco/visuals/results.py diff --git a/monoloco/eval/eval_kitti.py b/monoloco/eval/eval_kitti.py index 746480e..7afe5d2 100644 --- a/monoloco/eval/eval_kitti.py +++ b/monoloco/eval/eval_kitti.py @@ -15,7 +15,7 @@ from tabulate import tabulate from ..utils import get_iou_matches, get_task_error, get_pixel_error, check_conditions, get_category, split_training, \ parse_ground_truth -from ..visuals import print_results +from ..visuals import show_results, show_spread class EvalKitti: @@ -125,11 +125,10 @@ class EvalKitti: print('\n' + category.upper() + ':') self.show_statistics() - # Show/save results - self.printer(show=False) - - def printer(self, show): - print_results(self.dic_stats, show) + def printer(self, show, save): + if save or show: + show_results(self.dic_stats, show, save) + show_spread(self.dic_stats, show, save) def _parse_txts(self, path, category, method): boxes = [] diff --git a/monoloco/run.py b/monoloco/run.py index 2c1b5d8..ce0baba 100644 --- a/monoloco/run.py +++ b/monoloco/run.py @@ -86,6 +86,7 @@ def cli(): eval_parser.add_argument('--hidden_size', type=int, help='Number of hidden units in the model', default=256) eval_parser.add_argument('--n_stage', type=int, help='Number of stages in the model', default=3) eval_parser.add_argument('--show', help='whether to show statistic graphs', action='store_true') + eval_parser.add_argument('--save', help='whether to save statistic graphs', action='store_true') eval_parser.add_argument('--verbose', help='verbosity of statistics', action='store_true') eval_parser.add_argument('--stereo', help='include stereo baseline results', action='store_true') @@ -146,7 +147,7 @@ def main(): from .eval import EvalKitti kitti_eval = EvalKitti(verbose=args.verbose, stereo=args.stereo) kitti_eval.run() - kitti_eval.printer(show=args.show) + kitti_eval.printer(show=args.show, save=args.save) if 'nuscenes' in args.dataset: from .train import Trainer diff --git a/monoloco/visuals/__init__.py b/monoloco/visuals/__init__.py index 2e637d3..531874b 100644 --- a/monoloco/visuals/__init__.py +++ b/monoloco/visuals/__init__.py @@ -1,3 +1,3 @@ from .printer import Printer -from .results import print_results +from .figures import show_results, show_spread diff --git a/monoloco/visuals/figures.py b/monoloco/visuals/figures.py index 15d59ef..9c62b92 100644 --- a/monoloco/visuals/figures.py +++ b/monoloco/visuals/figures.py @@ -12,7 +12,7 @@ from matplotlib.patches import Ellipse from ..utils import get_task_error -def show_results(dic_stats, show=False): +def show_results(dic_stats, show=False, save=False): """ Visualize error as function of the distance and compare it with target errors based on human height analyses @@ -57,7 +57,7 @@ def show_results(dic_stats, show=False): plt.close() -def show_spread(dic_stats, show=False): +def show_spread(dic_stats, show=False, save=False): """Predicted confidence intervals and task error as a function of ground-truth distance""" phase = 'test' @@ -103,35 +103,12 @@ def show_spread(dic_stats, show=False): plt.legend() if show: plt.show() - else: + if save: plt.savefig(os.path.join(dir_out, 'spread_bi.png')) plt.close() -def show_method(): - """ method figure""" - std_1 = 0.75 - fig = plt.figure(1) - ax = fig.add_subplot(1, 1, 1) - - ell_3 = Ellipse((0, 2), width=std_1 * 2, height=0.3, angle=-90, color='b', fill=False, linewidth=2.5) - ell_4 = Ellipse((0, 2), width=std_1 * 3, height=0.3, angle=-90, color='r', fill=False, - linestyle='dashed', linewidth=2.5) - ax.add_patch(ell_4) - ax.add_patch(ell_3) - plt.plot(0, 2, marker='o', color='skyblue', markersize=9) - plt.plot([0, 3], [0, 4], 'k--') - plt.plot([0, -3], [0, 4], 'k--') - plt.xlim(-3, 3) - plt.ylim(0, 3.5) - plt.xticks([]) - plt.yticks([]) - plt.xlabel('X [m]') - plt.ylabel('Z [m]') - plt.savefig(os.path.join('docs', 'output_method.png')) - - -def show_task_error(): +def show_task_error(show, save): """Task error figure""" plt.figure(2) xx = np.linspace(0, 40, 100) @@ -159,7 +136,33 @@ def show_task_error(): plt.xlabel("Ground-truth distance from the camera $d_{gt}$ [m]") plt.ylabel("Localization error $\hat{e}$ due to human height variation [m]") plt.legend(loc=(0.01, 0.55)) # Location from 0 to 1 from lower left - plt.savefig(os.path.join('docs', 'task_error.png')) + if show: + plt.show() + if save: + plt.savefig(os.path.join('docs', 'task_error.png')) + + +def show_method(): + """ method figure""" + std_1 = 0.75 + fig = plt.figure(1) + ax = fig.add_subplot(1, 1, 1) + + ell_3 = Ellipse((0, 2), width=std_1 * 2, height=0.3, angle=-90, color='b', fill=False, linewidth=2.5) + ell_4 = Ellipse((0, 2), width=std_1 * 3, height=0.3, angle=-90, color='r', fill=False, + linestyle='dashed', linewidth=2.5) + ax.add_patch(ell_4) + ax.add_patch(ell_3) + plt.plot(0, 2, marker='o', color='skyblue', markersize=9) + plt.plot([0, 3], [0, 4], 'k--') + plt.plot([0, -3], [0, 4], 'k--') + plt.xlim(-3, 3) + plt.ylim(0, 3.5) + plt.xticks([]) + plt.yticks([]) + plt.xlabel('X [m]') + plt.ylabel('Z [m]') + plt.savefig(os.path.join('docs', 'output_method.png')) def target_error(xx, mm): @@ -218,7 +221,6 @@ def get_confidence_points(confidences, distances, errors): return distance_points, confidence_points - def height_distributions(): mu_men = 178 diff --git a/monoloco/visuals/results.py b/monoloco/visuals/results.py deleted file mode 100644 index e69de29..0000000