Skip to content

(Fixes PaddlePaddle/PaddleOCR#18064) fix: guard against KMeans n_clusters=0 crash in table recognition pipeline #5140

Open
Mane2305 wants to merge 1 commit into
PaddlePaddle:release/3.5from
Mane2305:fix/kmeans-zero-clusters-table-recognition
Open

(Fixes PaddlePaddle/PaddleOCR#18064) fix: guard against KMeans n_clusters=0 crash in table recognition pipeline #5140
Mane2305 wants to merge 1 commit into
PaddlePaddle:release/3.5from
Mane2305:fix/kmeans-zero-clusters-table-recognition

Conversation

@Mane2305

@Mane2305 Mane2305 commented May 27, 2026

Copy link
Copy Markdown

(Fixes PaddlePaddle/PaddleOCR#18064)

Problem

When using PPStructureV3 with engine="transformers" and
wireless_table_structure_recognition_model_name="SLANeXt_wireless",
the pipeline crashes with:

sklearn.utils._param_validation.InvalidParameterError:
The 'n_clusters' parameter of KMeans must be an int in the
range [1, inf). Got 0 instead.

Related issue: #5140

Root Cause

SLANeXt does not support resampling in the transformers engine
(logged as a warning), which causes zero cell detections.
This zero value propagates to KMeans as n_clusters=0 → crash.

Two code paths trigger this:

  1. N = html_pred_boxes_nums - len(cells_det_results) can be <= 0
  2. combine_rectangles() passes N directly to KMeans without validation

Fix

  1. Added early return guard in combine_rectangles() when N <= 0 or
    rectangles list is empty
  2. Added N <= 0 guard before calling combine_rectangles() in
    cells_det_results_reprocessing()

Testing

Tested locally with paddleocr==3.5.0, transformers==5.9.0 on Windows.
Pipeline now completes successfully instead of crashing.

Before fix:
[transformers] Resampling is not supported in SLANeXt
❌ InvalidParameterError: n_clusters=0

After fix:
[transformers] Resampling is not supported in SLANeXt
✅ Prediction done

@paddle-bot

paddle-bot Bot commented May 27, 2026

Copy link
Copy Markdown

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label May 27, 2026
@CLAassistant

CLAassistant commented May 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Mane2305

Mane2305 commented May 27, 2026

Copy link
Copy Markdown
Author

Local Testing Proof

Before fix (crash):

Screenshot 2026-05-27 065411

After fix (working):

Screenshot 2026-05-27 065113

Tested on:

  • OS: Windows 11
  • paddleocr: 3.5.2
  • transformers: 5.9.0
  • torch: 2.8.0
  • engine: transformers
  • model: SLANeXt_wireless

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

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PPStructureV3 not working with transformers

2 participants