Fixed deduplication in picodet_postprocess #15025
Open
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
When I tested your OCR with layout analysis I ran into a weird bug. I had this image:



Firstly, I ran the model with a score threshold 0.4 and the output was this image:
I was a little bit upset that the model did not find the title with high confidence so I lowered the threshold to 0.3 and the result is this image:
When I saw it, I knew that something was going wrong. When the threshold is lowered, the same or more bboxes can appear, but they cannot disappear.
I thought there was some bug in the nms function but I found a bug in the deduplication function. The function iterates bboxes and computes iou with all other bboxes. If there are overlapping bboxes one persists and the other is removed (marked as duplicate) but this approach is wrong. For example in this case:

In the first loop iteration, bboxes 0, 1, and 3 are removed. This does not make any sense. Bboxes 1 and 3 do not overlap at all. Additionally these bboxes overlap with only bbox 0 which is removed in the same iteration as well. The correct approach is to remove only tested bbox 0.
After this fix, the output is as expected:
