ssd.pytorch icon indicating copy to clipboard operation
ssd.pytorch copied to clipboard

why nms method is so slow?

Open Feywell opened this issue 6 years ago • 3 comments

I try to change this code to implement video object detecction. I find the test phase is slow. Then I visualize the time cost. I find nms is key reason.

nms time: 0.1834 sec. nms time: 0.1546 sec. nms time: 0.1525 sec. nms time: 0.1929 sec. nms time: 0.1670 sec. nms time: 0.1230 sec. nms time: 0.1894 sec. nms time: 0.1371 sec. nms time: 0.1648 sec. nms time: 0.1536 sec. nms time: 0.1382 sec. nms time: 0.1237 sec. nms time: 0.1603 sec. nms time: 0.1506 sec. nms time: 0.1619 sec. nms time: 0.1577 sec. nms time: 0.1479 sec. nms time: 0.1609 sec. nms time: 0.1520 sec. nms time: 0.1393 sec. nms time: 0.1535 sec. nms time: 0.1651 sec. nms time: 0.1500 sec. nms time: 0.1566 sec. nms time: 0.1418 sec. nms time: 0.1592 sec. nms time: 0.1417 sec. nms time: 0.1559 sec. nms time: 0.1424 sec. nms time: 0.1650 sec. cls time: 4.7556 sec.

My target is 30 classification, so it is so slow. How can I fix it?

Feywell avatar Dec 13 '18 03:12 Feywell

I have deprecated the original NMS function in this program. It seems the steps of running NMS with torch.Tensor, especially .cuda()???, is not optimized. Therefore, I replace it with another numpy version NMS implementation. I did it half year ago, so forgot details. You can search a reliable one on github.

KaiOtter avatar Dec 19 '18 08:12 KaiOtter

Maybe you could use the compiled nms from C++ code instead of the pure python implementation. @Feywell

d-li14 avatar Jan 01 '19 02:01 d-li14

hi~, i sovle this problem by change code like this: in ssd.py, change"self.detect = Detect(num_class, 0, 200, 0.01, 0.45)" to "self.detect = Detect(num_class, 0, 200, 0.15, 0.45)" This means that boxes with a conf less than 0.15 are filtered out before NMS. You can change this value according to your task. I think the reason for the slow detection speed is that the author sets this value too small, which will improve the detection accuracy, but it will also cause a large number of boxes to be processed in NMS stage, which will affect the detection speed.

fanyu546250151555481656 avatar Nov 08 '20 13:11 fanyu546250151555481656