Skip to content

Fix resize failure caused by zero-sized masks in PP-DocLayoutV3#45281

Open
zhang-prog wants to merge 1 commit intohuggingface:mainfrom
zhang-prog:feat/pp_doclayout_v3
Open

Fix resize failure caused by zero-sized masks in PP-DocLayoutV3#45281
zhang-prog wants to merge 1 commit intohuggingface:mainfrom
zhang-prog:feat/pp_doclayout_v3

Conversation

@zhang-prog
Copy link
Copy Markdown
Contributor

@zhang-prog zhang-prog commented Apr 7, 2026

Description

This PR fixes a boundary issue in the _extract_polygon_points_by_masks method of PP-DocLayoutV3.

When running inference with a low confidence threshold, or due to coordinate clipping during scaling, the extracted cropped_mask can sometimes have a size of 0 (empty array). This leads to a failure in subsequent operations (such as resize or polygon extraction).

7bc2a535a65c110746fbf2d29f79bb4f

Changes

Added a defensive check in _extract_polygon_points_by_masks to handle empty masks before processing:

cropped_mask = masks[i, y_start:y_end, x_start:x_end]
# New check: Handle cases where the mask is empty or contains no positive values
if cropped_mask.size == 0 or np.sum(cropped_mask) == 0:
    polygon_points.append(rect)
    continue

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

[For maintainers] Suggested jobs to run (before merge)

run-slow: pp_doclayout_v3

@zhang-prog
Copy link
Copy Markdown
Contributor Author

zhang-prog commented Apr 7, 2026

@vasqu @zucchini-nlp @molbap PTAL. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant