Skip to content

Fix IndexError in NMS when detection output is 1-dimensional#17685

Open
Mr-Neutr0n wants to merge 1 commit intoPaddlePaddle:mainfrom
Mr-Neutr0n:fix-nms-1d-array
Open

Fix IndexError in NMS when detection output is 1-dimensional#17685
Mr-Neutr0n wants to merge 1 commit intoPaddlePaddle:mainfrom
Mr-Neutr0n:fix-nms-1d-array

Conversation

@Mr-Neutr0n
Copy link
Contributor

Summary

  • Fixes PPStructureV3报错Indexerror: too many indices for array: array is 1-dimensianal, but 2 were indexed #17446
  • When PPStructureV3 detects zero or one object, the boxes array output from the model can be 1-dimensional, causing an IndexError: too many indices for array during NMS postprocessing when 2D slicing (e.g., boxes[:, -1]) is applied.
  • Added shape guards in hard_nms() to return an empty array for size-0 input and reshape 1D input to 2D for single-detection edge cases.
  • Added a similar guard after np.concatenate(picked_box_probs) in PicoDetPostProcess.__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 concatenated picked_box_probs if it becomes 1D.

Test plan

  • Verified with unit tests that hard_nms handles empty (0,5), 1D (5,), single 2D (1,5), and multi-box (N,5) inputs correctly.
  • Run PPStructureV3 inference on an image that produces 0 or 1 detections to confirm the IndexError no longer occurs.

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
@paddle-bot
Copy link

paddle-bot bot commented Feb 9, 2026

Thanks for your contribution!

@CLAassistant
Copy link

CLAassistant commented Feb 9, 2026

CLA assistant check
All committers have signed the CLA.

@Mr-Neutr0n
Copy link
Contributor Author

recheck

@TingquanGao
Copy link
Collaborator

TingquanGao commented Feb 28, 2026

感谢对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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PPStructureV3报错Indexerror: too many indices for array: array is 1-dimensianal, but 2 were indexed

4 participants