Fix max_box_w calculation bug in extract_polygon_points_by_masks#5147
Open
WenbinHou wants to merge 1 commit into
Open
Fix max_box_w calculation bug in extract_polygon_points_by_masks#5147WenbinHou wants to merge 1 commit into
WenbinHou wants to merge 1 commit into
Conversation
|
Thanks for your contribution! |
Author
|
Or ... should I target |
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.
Scope
This patch fixes one bug in the installed PaddleX package inside
paddlex/inference/models/layout_analysis/processors.py.The patched function is
extract_polygon_points_by_masks().Problem
The original code computed:
Within this function, each row in
boxesis treated as:The same function later unpacks:
So
boxes[:, 4] - boxes[:, 3]isx_max - y_min, not width.That value is then used as the fallback
max_allowed_distin the polygonvertex extraction path:
This affects
extract_custom_vertices()viamask2polygon(), so the mistakechanges how many intermediate vertices are kept or inserted on long polygon
edges.
Fix
The local fix replaces that line with:
This is the correct
x_max - x_minwidth calculation.Validation
I checked this in two ways.
1. Static code check
Inside the same function, the code clearly treats
boxes[i, 2:6]asx_min, y_min, x_max, y_max. Under that schema, the original expression mixesx and y axes and cannot represent width.
2. Real-image A/B comparison
I compared the current implementation against a corrected version on
Real5-OmniDocBench, using the first 20 images from each subset:Real5-OmniDocBench-IlluminationReal5-OmniDocBench-ScanningReal5-OmniDocBench-Screen-PhotographyReal5-OmniDocBench-SkewReal5-OmniDocBench-WarpingTotals:
100images checked10images changed underlayout_shape_mode='poly'11polygons changed underlayout_shape_mode='poly'1image changed underlayout_shape_mode='auto'2polygons changed underlayout_shape_mode='auto'The computed
current_max_box_w / fixed_max_box_wratio ranged from about0.736to1.958, which is consistent with a coordinate-indexing mistake,not an intentional heuristic.
Representative cases:
Real5-OmniDocBench-Warping/PPT_1637904769_page_008.pngtextpolygon changed from8vertices to9Real5-OmniDocBench-Skew/PPT_B14_Claeys_Consistent Presentation of Images_v2_page_013.pngtextpolygons changed under bothpolyandauto10vertices to1210vertices to11Why this matters
This bug does not change the model forward pass itself. It affects the Python
postprocess stage that converts:
masks -> contour -> polygon_pointsSpecifically, it changes the geometric simplification / densification threshold
used after contour extraction, so the resulting polygons may lose or gain
vertices unexpectedly.