From cd96a26f67bfbb9b0efe6e0e2b229d0b46b4e3e6 Mon Sep 17 00:00:00 2001 From: giuros01 Date: Wed, 3 Oct 2018 12:44:35 +0100 Subject: COMPMID-1329: Add support for GenerateProposals operator in CL Change-Id: Ib0798cc17496b7817f5b5769b25d98913a33a69d --- .../CPPBoxWithNonMaximaSuppressionLimitKernel.cpp | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src/core/CPP/kernels') diff --git a/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp b/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp index 89413fcca4..2b9934cfa8 100644 --- a/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp +++ b/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp @@ -54,7 +54,7 @@ std::vector SoftNMS(const ITensor *proposals, std::vector> & areas[i] = (x2[i] - x1[i] + 1.0) * (y2[i] - y1[i] + 1.0); } - // Note: Soft NMS scores have already been initialize with input scores + // Note: Soft NMS scores have already been initialized with input scores while(!inds.empty()) { @@ -150,17 +150,21 @@ std::vector NonMaximaSuppression(const ITensor *proposals, std::vector for(unsigned int j = 0; j < sorted_indices_temp.size(); ++j) { - const auto xx1 = std::max(x1[sorted_indices_temp.at(j)], x1[i]); - const auto yy1 = std::max(y1[sorted_indices_temp.at(j)], y1[i]); - const auto xx2 = std::min(x2[sorted_indices_temp.at(j)], x2[i]); - const auto yy2 = std::min(y2[sorted_indices_temp.at(j)], y2[i]); - - const auto w = std::max((xx2 - xx1 + 1.f), 0.f); - const auto h = std::max((yy2 - yy1 + 1.f), 0.f); - const auto inter = w * h; - const auto ovr = inter / (areas[i] + areas[sorted_indices_temp.at(j)] - inter); - - if(ovr <= info.nms()) + const float xx1 = std::max(x1[sorted_indices_temp.at(j)], x1[i]); + const float yy1 = std::max(y1[sorted_indices_temp.at(j)], y1[i]); + const float xx2 = std::min(x2[sorted_indices_temp.at(j)], x2[i]); + const float yy2 = std::min(y2[sorted_indices_temp.at(j)], y2[i]); + + const float w = std::max((xx2 - xx1 + 1.f), 0.f); + const float h = std::max((yy2 - yy1 + 1.f), 0.f); + const float inter = w * h; + const float ovr = inter / (areas[i] + areas[sorted_indices_temp.at(j)] - inter); + const float ctr_x = xx1 + (w / 2); + const float ctr_y = yy1 + (h / 2); + + // If suppress_size is specified, filter the boxes based on their size and position + const bool keep_size = !info.suppress_size() || (w >= info.min_size() && h >= info.min_size() && ctr_x < info.im_width() && ctr_y < info.im_height()); + if(ovr <= info.nms() && keep_size) { new_indices.push_back(j); } @@ -214,8 +218,9 @@ void CPPBoxWithNonMaximaSuppressionLimitKernel::run_nmslimit() for(int b = 0; b < batch_size; ++b) { const int num_boxes = _batch_splits_in == nullptr ? 1 : static_cast(*reinterpret_cast(_batch_splits_in->ptr_to_element(Coordinates(b)))); - // Skip first class - for(int j = 1; j < num_classes; ++j) + // Skip first class if there is more than 1 except if the number of classes is 1. + const int j_start = (num_classes == 1 ? 0 : 1); + for(int j = j_start; j < num_classes; ++j) { std::vector cur_scores(scores_count); std::vector inds; @@ -290,7 +295,7 @@ void CPPBoxWithNonMaximaSuppressionLimitKernel::run_nmslimit() // Write results int cur_out_idx = 0; - for(int j = 1; j < num_classes; ++j) + for(int j = j_start; j < num_classes; ++j) { auto &cur_keep = keeps[j]; auto cur_out_scores = reinterpret_cast(_scores_out->ptr_to_element(Coordinates(cur_start_idx + cur_out_idx))); -- cgit v1.2.1