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.
相关 Issue
PaddlePaddle/PaddleOCR#17133
问题描述
使用 PPStructureV3 处理包含多个表格的图片时,单元格检测结果会出现混乱。问题原因如下:
后处理 NMS 排序问题:当多个表格裁剪区域在单个批次中处理时,NMS 后检测结果的排序可能会发生变化,导致单元格分配不再与其原始表格对齐。
错误的分组逻辑:原代码依赖扁平化预测结果的顺序(使用
box_nums切片),而不是使用批次索引(batch_inds)将检测结果分组回其源表格。单表格正常,多表格失败:单个表格时一切正常,但一旦多个裁剪区域被批处理在一起,就会出现单元格混合。
解决方案
将分组逻辑改为依赖每个检测结果的
batch_idx(batch_inds),而不是依赖扁平化预测结果的顺序。这确保了即使在 NMS 后重新排序的情况下也能正确分组。实现细节
优先级 1:从原始 RT-DETR 输出中提取 batch_inds
batch_inds(与 boxes 长度匹配的 1D 整数数组)batch_inds和 masks(Instance Segmentation 中通常是 3D 数组)优先级 2:从 box_nums 构造 batch_inds(回退方案)
len(boxes) == sum(box_nums)时构造batch_inds(boxes 未被 NMS 重新排序)batch_inds不可用的情况提供了回退方案优先级 3:使用 batch_inds 进行分组
batch_idx分组检测结果,而不是顺序切片回退:原始方法
batch_inds,则回退到原始的box_nums切片方法以保持向后兼容性修改内容
修改的文件
paddlex/inference/models/object_detection/predictor.py_format_output()方法,使用batch_inds对检测结果进行分组batch_inds的逻辑box_nums构造batch_inds的回退机制关键代码变更