GitHub#465 Fix NonMaxSuppression
authorantkillerfarm <antkillerfarm@gmail.com>
Thu, 15 Oct 2020 03:02:07 +0000 (11:02 +0800)
committermike.kelly <mike.kelly@arm.com>
Fri, 23 Oct 2020 10:39:21 +0000 (10:39 +0000)
If visited flag set true, it should not be visited any more.
For example, if we put 10 boxes (ordered by score) into NonMaxSuppression:
* Step1: Suppose Box 2/3/6/8 are suppressed by Box 1. Box 4/5/7/9/10 survived.
* Step2: Correct way: We use Box 4 to suppress the survive boxes.
         Prior to this commit: Box 4 may be suppressed by Box 2,
          even Box 2 is already suppressed by Box 1...

Signed-off-by: Antkillerfarm <antkillerfarm@gmail.com>
Change-Id: I38d7a84287649827a16565748592fb562b4df5d5

src/backends/reference/workloads/DetectionPostProcess.cpp

index f80f20a..2108efe 100644 (file)
@@ -85,14 +85,14 @@ std::vector<unsigned int> NonMaxSuppression(unsigned int numBoxes,
         if (!visited[sortedIndices[i]])
         {
             outputIndices.push_back(indicesAboveThreshold[sortedIndices[i]]);
-        }
-        for (unsigned int j = i + 1; j < numAboveThreshold; ++j)
-        {
-            unsigned int iIndex = indicesAboveThreshold[sortedIndices[i]] * 4;
-            unsigned int jIndex = indicesAboveThreshold[sortedIndices[j]] * 4;
-            if (IntersectionOverUnion(&boxCorners[iIndex], &boxCorners[jIndex]) > nmsIouThreshold)
+            for (unsigned int j = i + 1; j < numAboveThreshold; ++j)
             {
-                visited[sortedIndices[j]] = true;
+                unsigned int iIndex = indicesAboveThreshold[sortedIndices[i]] * 4;
+                unsigned int jIndex = indicesAboveThreshold[sortedIndices[j]] * 4;
+                if (IntersectionOverUnion(&boxCorners[iIndex], &boxCorners[jIndex]) > nmsIouThreshold)
+                {
+                    visited[sortedIndices[j]] = true;
+                }
             }
         }
     }