ZFTurbo / Weighted-Boxes-Fusion

Set of methods to ensemble boxes from different object detection models, including implementation of "Weighted boxes fusion (WBF)" method.
MIT License
1.7k stars 237 forks source link

Speed up find_matching_box bottleneck #48

Closed bartonp2 closed 2 years ago

bartonp2 commented 2 years ago

When using weighted boxes fusion with a couple thousand detections it quickly becomes very slow requiring significantly longer than the inference. The bottleneck turned out to be the find_matching_box function which is called n*n times for n detections. Vectorisation of this function with numpy speeds up the function by a factor of around 100 and makes the weighted boxes fusion time negligible next to the inference time.

ZFTurbo commented 2 years ago

I can confirm that for example_oid.py I observe the speed up. 285 sec before -> 242 sec after. Not x100 but something. )

Great work!

bartonp2 commented 2 years ago

I guess it becomes more prominent with more detections per image since it scales quadratically.

ZFTurbo commented 2 years ago

For COCO benchmark it's even better: https://github.com/ZFTurbo/Weighted-Boxes-Fusion/tree/master/benchmark

1055 sec vs 643 sec. Speedup almost x2 times. Probably it's because there are more models to ensemble.

ZFTurbo commented 2 years ago

I think more vectorization could lead to GPU implementation which will be faster than CPU. My previous attempt with PyTorch failed.