From 030e14d7823be2e7adf97c2dc5ed8f3dd03da7b2 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Fri, 25 Aug 2017 11:41:29 +0200 Subject: [PATCH 1/2] spalla overlap optimization --- src/Region.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Region.cpp b/src/Region.cpp index 5e6c80a..5b65348 100644 --- a/src/Region.cpp +++ b/src/Region.cpp @@ -186,6 +186,8 @@ int nms_comparator(const void *pa, const void *pb) { return 0; } float overlap(float x1, float w1, float x2, float w2) { + /* + //SLOW METHOD float l1 = x1 - w1/2; float l2 = x2 - w2/2; float left = l1 > l2 ? l1 : l2; @@ -193,6 +195,16 @@ float overlap(float x1, float w1, float x2, float w2) { float r2 = x2 + w2/2; float right = r1 < r2 ? r1 : r2; return right - left; + */ + + //SPALLA METHOD + float l; + w1 < w2? l=w1 : l=w2; + float d = fabs(x1 - x2); + float k = fabs(w1 - w2)/2; + if (d <= k) return l; + else if (d <= k +l) return l - (d-k); + else return 0; } float box_intersection(box a, box b) { float w = overlap(a.x, a.w, b.x, b.w); @@ -235,7 +247,6 @@ void RegionInterpret::interpretData(dnnType *data_h) { get_region_boxes(data_h, imW, imH, output_dim.w, output_dim.h, thresh, probs, boxes, 0, 0, 0.5, 1); //delete repeats -/* for(int i = 0; i < tot; ++i){ s[i].index = i; s[i].cl = classes; @@ -254,7 +265,6 @@ void RegionInterpret::interpretData(dnnType *data_h) { } } } -*/ res_boxes_n = 0; //print results From 6c2f6bcf2e1f1ee0c1e638adc1c0fb33f3b45d68 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Fri, 25 Aug 2017 15:07:47 +0200 Subject: [PATCH 2/2] optimization2 --- src/Region.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Region.cpp b/src/Region.cpp index 5b65348..84c0332 100644 --- a/src/Region.cpp +++ b/src/Region.cpp @@ -208,8 +208,9 @@ float overlap(float x1, float w1, float x2, float w2) { } float box_intersection(box a, box b) { float w = overlap(a.x, a.w, b.x, b.w); + if(w <= 0) return 0; float h = overlap(a.y, a.h, b.y, b.h); - if(w < 0 || h < 0) return 0; + if(h <= 0) return 0; float area = w*h; return area; } @@ -219,6 +220,8 @@ float box_union(box a, box b) { return u; } float box_iou(box a, box b) { + if(fabs(a.x - b.x) > (a.w+b.w)/2 || fabs(a.y - b.y) > (a.h+b.h)/2) + return 0; return box_intersection(a, b)/box_union(a, b); } int max_index(float *a, int n) { @@ -253,6 +256,7 @@ void RegionInterpret::interpretData(dnnType *data_h) { s[i].probs = probs; } qsort(s, tot, sizeof(sortable_bbox), nms_comparator); + TIMER_START for(int i = 0; i < tot; ++i){ if(probs[s[i].index][classes] == 0) continue; box a = boxes[s[i].index]; @@ -265,7 +269,7 @@ void RegionInterpret::interpretData(dnnType *data_h) { } } } - + TIMER_STOP res_boxes_n = 0; //print results for(int i = 0; i < tot; ++i){