Fix IndexError in NMS when detection output is 1-dimensional#17685
Open
Mr-Neutr0n wants to merge 1 commit intoPaddlePaddle:mainfrom
Open
Fix IndexError in NMS when detection output is 1-dimensional#17685Mr-Neutr0n wants to merge 1 commit intoPaddlePaddle:mainfrom
Mr-Neutr0n wants to merge 1 commit intoPaddlePaddle:mainfrom
Conversation
When the model detects zero or one object, the boxes array can be
1-dimensional, causing an IndexError ("too many indices for array")
when attempting 2D slicing like boxes[:, -1].
Add shape checks in hard_nms to handle edge cases:
- Return empty array when input has size 0
- Reshape 1D input to 2D (1, -1) for single detection
Also guard against 1D array from np.concatenate in the
PicoDetPostProcess pipeline when only one box is picked.
Fixes PaddlePaddle#17446
|
Thanks for your contribution! |
Contributor
Author
|
recheck |
Collaborator
|
感谢对PaddleOCR的支持。 不过我理解,该问题的根本原因是在PP-StructureV3:对于检测到0个、1个版面元素的情况,PP-StructureV3 中输入给后续OCR的数据格式有问题,是这样吗? 我们会排查确认一下,因此该PR暂时先不合入。 Thank you for your support of PaddleOCR. However, I understand that the fundamental cause of this issue is in PP-StructureV3: there is a problem with the data format input to the subsequent OCR for cases where 0 or 1 layout elements are detected. We will confirm this, so this PR will not be merged for the time being. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
boxesarray output from the model can be 1-dimensional, causing anIndexError: too many indices for arrayduring NMS postprocessing when 2D slicing (e.g.,boxes[:, -1]) is applied.hard_nms()to return an empty array for size-0 input and reshape 1D input to 2D for single-detection edge cases.np.concatenate(picked_box_probs)inPicoDetPostProcess.__call__to ensure the concatenated result is always 2D.Changes
ppocr/postprocess/picodet_postprocess.py:hard_nms: early return for empty input; reshape 1D to(1, -1)before slicing.PicoDetPostProcess.__call__: reshape concatenatedpicked_box_probsif it becomes 1D.Test plan
hard_nmshandles empty (0,5), 1D (5,), single 2D (1,5), and multi-box (N,5) inputs correctly.