Fix objectness is not assigned in dnn::region_layer#22660
Fix objectness is not assigned in dnn::region_layer#22660asmorkalov merged 1 commit intoopencv:4.xfrom zhouzq-thu:4.x
Conversation
Fix objectness (dstData[index + 4]) is not assigned if new_coords == 1.
|
@zhouzq-thu Could you point the issue, enabled model, or better to add test for the fix? |
|
In the latest 4.x branch, the objectness in the region_layer is only assigned at But if YOLOv4 model is used (if |
|
@AlexeyAB, could you validate please? |
| dstData[box_index + 4] = srcData[p_index]; | ||
|
|
||
| scale = srcData[p_index]; | ||
| if (classfix == -1 && scale < thresh) |
There was a problem hiding this comment.
If I understand correctly, new_coords only have affects on how we calculate the width and height of bboxes. It does not relate to whether objectness should be kept or not. See these lines from darknet: https://github.com/AlexeyAB/darknet/blob/62e5549cef53bd11890808615e0bfae59cfd4491/src/yolo_layer.c#L132-L153
By they way, the scale in line 322 should be the objectness as you mentioned. Objectness is only used to calculate the final object score, and hence we do not need to keep it in the output.
There was a problem hiding this comment.
- The
dstData[index + 4]is uninitialized ifnew_coords=1, but initialized ifnew_coords=0. I think it is not good. - If you have
dstData[index + 4]values, you can optimize NMS by filtering some boxes (dstData[index + 4] < score_thresh), no need to find the maximum of all classes probabilities and check if it greater thanscore_threshfor each box.
ping @AlexeyAB
|
@zhouzq-thu @fengyuentau Thanks for the patch and review. I made small investigation and outcome is the following:
So, the proposed patch is relevant and correct. |
Thanks for the information. It is indeed should be set in case of initialization. Just want to emphasize that the following opencv/modules/dnn/src/layers/region_layer.cpp Lines 357 to 390 in ebde9a5 because the objectness score (scale in the following code piece) has been blended into the class score with opencv/modules/dnn/src/layers/region_layer.cpp Lines 321 to 331 in ebde9a5 |
fengyuentau
left a comment
There was a problem hiding this comment.
👍 Approve in case of initialization.
|
I dig in tests and extra and found out that |
Fix objectness (dstData[index + 4]) is not assigned if new_coords == 1.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.