Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] NMS update #4990

Closed
wants to merge 21 commits into from
Closed

Conversation

SemyonBevzuk
Copy link
Contributor

Added "score_threshold" and "max_num" for the updated NMS.
This significantly improves performance in ONNX Runtime and reduces export times.
The table shows the average execution time of the NMS operation and the total inference time of the RetinaNet model:

RetinaNet (ONNX Runtime) Befor (s) Now (s)
NMS time 15.99 0.0002574
Total time 16.78 0.76766

This PR should be merged after merging this PR into mmcv.

@CLAassistant
Copy link

CLAassistant commented Apr 16, 2021

CLA assistant check
All committers have signed the CLA.

@shinya7y
Copy link
Contributor

The order of score_factors seems inconsistent.
#4473

@SemyonBevzuk
Copy link
Contributor Author

The order of score_factors seems inconsistent.
#4473

Yes, filtering by score_thr after multiplying by score_factor significantly degrades the quality metrics.
I have fixed this problem with APs drop in PyTorch. Here is the output of the tools/test.py:

python tools/test.py configs/yolo/yolov3_d53_mstrain-608_273e_coco.py  checkpoints/yolov3/yolov3_d53_mstrain-608_273e_coco-139f5633.pth --eval bbox

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.335
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=1000 ] = 0.563
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=1000 ] = 0.352
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.196
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = 0.364
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.436
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.460
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 ] = 0.460
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=1000 ] = 0.460
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.297
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = 0.483
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.586
OrderedDict([('bbox_mAP', 0.335), ('bbox_mAP_50', 0.563), ('bbox_mAP_75', 0.352), ('bbox_mAP_s', 0.196), ('bbox_mAP_m', 0.364), ('bbox_mAP_l', 0.436), ('bbox_mAP_copypaste', '0.335 0.563 0.352 0.196 0.364 0.436')])

@shinya7y
Copy link
Contributor

Is the order issue unavoidable if torch.onnx.is_in_onnx_export()?

@ZwwWayne
Copy link
Collaborator

Hi @SemyonBevzuk ,
Thanks for your kind contribution. The unit tests fail, can you check that?

@SemyonBevzuk
Copy link
Contributor Author

Hi @SemyonBevzuk ,
Thanks for your kind contribution. The unit tests fail, can you check that?

Hi @ZwwWayne,
Yes, unit tests fail, as this PR uses functionality from this PR in mmcv.
After adding new arguments (score_threshold, max_num) to the NMS operation, the unit tests should pass.

@RunningLeon
Copy link
Collaborator

@SemyonBevzuk Hi, you could install pre-commit in your environment and it would check the code style before each commit.

setup.cfg Outdated Show resolved Hide resolved
@RunningLeon RunningLeon requested a review from hhaAndroid May 6, 2021 06:09
@RunningLeon
Copy link
Collaborator

@SemyonBevzuk There may be multiple places where batched_nms is called and max_num should be updated. For instance,
trident_roi_head:

det_bboxes, keep = batched_nms(nms_bboxes, nms_scores, nms_inds,

@SemyonBevzuk
Copy link
Contributor Author

@SemyonBevzuk There may be multiple places where batched_nms is called and max_num should be updated. For instance,
trident_roi_head:

det_bboxes, keep = batched_nms(nms_bboxes, nms_scores, nms_inds,

Yes, I will look at other places, where batched_nms is called.

@AronLin
Copy link
Contributor

AronLin commented May 24, 2021

With PR #4990 and open-mmlab/mmcv#957, I evaluated some released pytorch models.
The results shows that this PR does not adversely affect the original performance.

Model Box AP Seg AP ori Box AP ori Seg AP
mask_rcnn_r50_fpn_1x_coco 38.2 34.7 38.2 34.7
fcos_r50_caffe_fpn_gn-head_1x_coco 36.6 - 36.6 -
cascade_rcnn_r50_fpn_1x_coco 40.3 - 40.3 -
retinanet_r50_fpn_1x_coco 36.5 - 36.5 -
faster_rcnn_r50_fpn_1x_coco 37.4 - 37.4 -
yolov3_d53_mstrain-608_273e_coco 33.5 - 33.4 -

@AronLin
Copy link
Contributor

AronLin commented May 25, 2021

ONNX Runtime performance with #4990 and open-mmlab/mmcv#957:

Model Box AP ori Box AP pytorch
ssd300 25.6 25.6 25.6
retinanet_r50_fpn_1x_coco 36.4 36.4 36.5
yolov3_d53_mstrain-608_273e_coco 33.5 33.5 33.5

@RunningLeon RunningLeon requested a review from ZwwWayne May 25, 2021 07:22
@ZwwWayne ZwwWayne mentioned this pull request Jun 3, 2021
11 tasks
@RunningLeon RunningLeon marked this pull request as ready for review June 7, 2021 06:42
@RunningLeon RunningLeon added the WIP Working in progress label Jun 7, 2021
@RunningLeon
Copy link
Collaborator

@SemyonBevzuk Hi, since open-mmlab/mmcv#957 is merged. Could we fix conflicts and CI errors in this PR? Thanks a lot.

@codecov
Copy link

codecov bot commented Jun 15, 2021

Codecov Report

Attention: Patch coverage is 46.66667% with 8 lines in your changes missing coverage. Please review.

Project coverage is 65.05%. Comparing base (a4e04e8) to head (2d2223c).
Report is 605 commits behind head on master.

Files with missing lines Patch % Lines
mmdet/models/dense_heads/cascade_rpn_head.py 0.00% 3 Missing ⚠️
mmdet/models/dense_heads/fovea_head.py 0.00% 2 Missing ⚠️
mmdet/core/post_processing/bbox_nms.py 83.33% 0 Missing and 1 partial ⚠️
mmdet/models/dense_heads/rpn_head.py 66.66% 0 Missing and 1 partial ⚠️
mmdet/models/roi_heads/trident_roi_head.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4990      +/-   ##
==========================================
- Coverage   65.07%   65.05%   -0.02%     
==========================================
  Files         275      275              
  Lines       21238    21249      +11     
  Branches     3532     3536       +4     
==========================================
+ Hits        13820    13824       +4     
- Misses       6669     6673       +4     
- Partials      749      752       +3     
Flag Coverage Δ
unittests 65.02% <46.66%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RunningLeon RunningLeon requested a review from jshilong June 16, 2021 03:21
@RunningLeon
Copy link
Collaborator

@ZwwWayne @jshilong @hhaAndroid Hi, guys, do you have a conclusion and an agreed decision on this PR?

@SemyonBevzuk SemyonBevzuk closed this by deleting the head repository Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ONNX WIP Working in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants