Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
vasqu merged 4 commits into
huggingface:mainfrom
zhang-prog:feat/pp_doclayout_v3
Apr 9, 2026
Merged

Fix resize failure caused by zero-sized masks in PP-DocLayoutV3#45281
vasqu merged 4 commits into
huggingface:mainfrom
zhang-prog:feat/pp_doclayout_v3

Conversation

@zhang-prog

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

Copy link
Copy Markdown
Contributor

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

@zhang-prog

zhang-prog commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

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

@vasqu vasqu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a small test to the image processor for such a case (dummy values). Otherwise, lgtm

@zhang-prog

Copy link
Copy Markdown
Contributor Author

@vasqu Done, PTAL

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: pp_doclayout_v3

@vasqu vasqu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just added a small comment for reference to this PR merging

@vasqu vasqu merged commit 4cb5595 into huggingface:main Apr 9, 2026
22 checks passed
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

sirzechs66 pushed a commit to sirzechs66/transformers that referenced this pull request Apr 18, 2026
…ingface#45281)

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

* add small test

* add small reference to PR

---------

Co-authored-by: vasqu <[email protected]>
Co-authored-by: Anton Vlasjuk <[email protected]>
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.

3 participants