You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-28Lines changed: 20 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,21 +3,21 @@ Speeding up Non Maximum Suppresion ran on very large images by a several folds f
3
3
This project becomes useful in the case of very high dimensional images data, when the amount of predicted instances to prune becomes considerable (> 10,000 objects).
@@ -53,7 +53,7 @@ Note: confidence score are not represented on this image.
53
53
<figcaption>NMS example (source https://www.pyimagesearch.com/2015/02/16/faster-non-maximum-suppression-python/)</figcaption></center>
54
54
</p> -->
55
55
A nice introduction of the non maximum suppression algorithm can be found here: https://www.coursera.org/lecture/convolutional-neural-networks/non-max-suppression-dvrjH.
56
-
Basically, NMS discards redundant boxes in a set of predicted instances. It is an essential step of object detection pipelines.
56
+
Basically, NMS discards redundant boxes in a set of predicted instances. It is an essential - and often unavoidable, step of object detection pipelines.
57
57
58
58
59
59
## Scaling up the Non Maximum Suppression process
@@ -69,14 +69,15 @@ A more natural way to speed up NMS could be through parallelization, like it is
69
69
3. The process remains quadratic, and does not scale well.
70
70
### LSNMS
71
71
This project offers a way to overcome the aforementioned issues elegantly:
72
-
1. Before the NMS process, a binary 2-dimensional tree is built on bounding boxes centroids (in a `O(n*log(n))` time)
73
-
2. At each NMS step, boxes distant from less than a fixed radius of the considered box are queried in the tree (in a `O(log(n))` complexity time), and only those neighbors are considered in the pruning process: IoU computation + pruning if necessary. Hence, the overall NMS process is turned from a `O(n**2)` into a `O(n * log(n))` process. See a comparison of run times on the graph below (results obtained on sets of instances whose coordinates vary between 0 and 100,000 (x and y)). Note that the choice of the radius neighborhood is essential: the bigger the radius, the closer one is from the naive NMS process. On the other hand, if this radius is too small, one risks to produce wrong results. A safe rule of thumb is to choose a radius approximately equalling the size of the biggest bounding box of the dataset.
72
+
1. Before the NMS process, a R-Tree is built on bounding boxes (in a `O(n*log(n))` time)
73
+
2. At each NMS step, only boxes overlapping with the current highest scoring box are queried in the tree (in a `O(log(n))` complexity time), and only those neighbors are considered in the pruning process: IoU computation + pruning if necessary. Hence, the overall NMS process is turned from a `O(n**2)` into a `O(n * log(n))` process. See a comparison of run times on the graph below (results obtained on sets of instances whose coordinates vary between 0 and 10,000 (x and y)).
74
+
A nice introduction of R-Tree can be found here: https://iq.opengenus.org/r-tree/.
74
75
75
76
Note that the timing reported below are all inclusive: it notably includes the tree building process, otherwise comparison would not be fair.
<figcaption>Run times (on a virtual image of 10kx10k pixels)</figcaption></center>
80
81
</p>
81
82
82
83
@@ -89,7 +90,7 @@ For the sake of speed, this repo is entirely (including the binary tree) built u
89
90
For the sake of completeness, this repo also implements a variant of the Weighted Box Clustering algorithm (from https://arxiv.org/pdf/1811.08661.pdf). Since NMS can artificially push up confidence scores (by selecting only the highest scoring box per instance), WBC overcomes this by averaging box coordinates and scores of all the overlapping boxes (instead of discarding all the non-maximally scored overlaping boxes).
90
91
91
92
## Disclaimer:
92
-
1. The binary tree implementation could probably be further optimized, see implementation notes below.
93
+
1. The tree implementation could probably be further optimized, see implementation notes below.
93
94
2. Much simpler implementation could rely on existing KD-Tree implementations (such as sklearn's), query the tree before NMS, and tweak the NMS process to accept tree query's result. This repo implements it from scratch in full numba for the sake of completeness and elegance.
94
95
3. The main parameter deciding the speed up brought by this method is (along with the amount of instances) the **density** of boxes over the image: in other words, the amount of overlapping boxes trimmed at each step of the NMS process. The lower the density of boxes, the higher the speed up factor.
95
96
4. Due to numba's compiling process, the first call to each jitted function might lag a bit, second and further function calls (per python session) should not suffer this overhead.
<figcaption>Tree building times comparison</figcaption></center>
124
-
</p>
125
-
126
-
127
121
## Performances
128
-
The BallTree implemented in this repo was timed against scikit-learn's `neighbors` one. Note that runtimes are not fair to compare since sklearn implementation allows for node to contain
122
+
The RTree implemented in this repo was timed against scikit-learn's `neighbors` one. Note that runtimes are not fair to compare since sklearn implementation allows for node to contain
129
123
between `leaf_size` and `2 * leaf_size` datapoints. To account for this, I timed my implementation against sklearn tree with `int(0.67 * leaf_size)` as `leaf_size`.
0 commit comments