From 0c85be0f2d4387d96de6a9cc965545347efbbf44 Mon Sep 17 00:00:00 2001 From: Randall Bohn Date: Wed, 24 Jan 2018 09:11:36 -0700 Subject: [PATCH] refactor interval_overlap() remove nested if clauses --- frontend.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/frontend.py b/frontend.py index 35dccb8d2..1a7e3c46e 100644 --- a/frontend.py +++ b/frontend.py @@ -274,17 +274,10 @@ def bbox_iou(self, box1, box2): def interval_overlap(self, interval_a, interval_b): x1, x2 = interval_a x3, x4 = interval_b - - if x3 < x1: - if x4 < x1: - return 0 - else: - return min(x2,x4) - x1 - else: - if x2 < x3: - return 0 - else: - return min(x2,x4) - x3 + # overlap is lesser of x4, x2 minus the greater of x3, x1 + overlap = min(x4,x2) - max(x3,x1) + # overlap should be >= 0 (otherwise there is no overlap) + return max(overlap, 0) def decode_netout(self, netout, obj_threshold=0.3, nms_threshold=0.3): grid_h, grid_w, nb_box = netout.shape[:3]