zhreshold closed pull request #10794: fix topk nms in multibox_detection
operator
URL: https://github.com/apache/incubator-mxnet/pull/10794
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/src/operator/contrib/multibox_detection.cc
b/src/operator/contrib/multibox_detection.cc
index a2e681a8e60..112c033552e 100644
--- a/src/operator/contrib/multibox_detection.cc
+++ b/src/operator/contrib/multibox_detection.cc
@@ -142,7 +142,11 @@ inline void MultiBoxDetectionForward(const Tensor<cpu, 3,
DType> &out,
DType *ptemp = temp_space.dptr_ + nbatch * num_anchors * 6;
int nkeep = static_cast<int>(sorter.size());
if (nms_topk > 0 && nms_topk < nkeep) {
+ // keep topk detections
nkeep = nms_topk;
+ for (int i = nkeep; i < valid_count; ++i) {
+ p_out[i * 6] = -1;
+ }
}
for (int i = 0; i < nkeep; ++i) {
for (int j = 0; j < 6; ++j) {
@@ -150,10 +154,10 @@ inline void MultiBoxDetectionForward(const Tensor<cpu, 3,
DType> &out,
}
}
// apply nms
- for (int i = 0; i < valid_count; ++i) {
+ for (int i = 0; i < nkeep; ++i) {
int offset_i = i * 6;
if (p_out[offset_i] < 0) continue; // skip eliminated
- for (int j = i + 1; j < valid_count; ++j) {
+ for (int j = i + 1; j < nkeep; ++j) {
int offset_j = j * 6;
if (p_out[offset_j] < 0) continue; // skip eliminated
if (force_suppress || (p_out[offset_i] == p_out[offset_j])) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services