opendatalab/MinerU · error · ValueError
Shape of table bounding boxes is not between in 4 or 8.
Error message
Shape of table bounding boxes is not between in 4 or 8.
What it means
Raised by the UNet table recognizer's visualization routine when table_cell_bboxes has a second dimension that is neither 4 (axis-aligned boxes: x1,y1,x2,y2) nor 8 (quad polygons: 4 xy points). The drawing code dispatches on bboxes.shape[1] and can only draw rectangles (4) or polylines (8).
Source
Thrown at mineru/model/table/rec/unet_table/utils.py:381
):
if save_html_path:
html_with_border = self.insert_border_style(table_results.pred_html)
self.save_html(save_html_path, html_with_border)
table_cell_bboxes = table_results.cell_bboxes
table_logic_points = table_results.logic_points
if table_cell_bboxes is None:
return None
img = self.load_img(img_path)
dims_bboxes = table_cell_bboxes.shape[1]
if dims_bboxes == 4:
drawed_img = self.draw_rectangle(img, table_cell_bboxes)
elif dims_bboxes == 8:
drawed_img = self.draw_polylines(img, table_cell_bboxes)
else:
raise ValueError("Shape of table bounding boxes is not between in 4 or 8.")
if save_drawed_path:
self.save_img(save_drawed_path, drawed_img)
if save_logic_path:
polygons = [[box[0], box[1], box[4], box[5]] for box in table_cell_bboxes]
self.plot_rec_box_with_logic_info(
img, save_logic_path, table_logic_points, polygons
)
return drawed_img
def insert_border_style(self, table_html_str: str):
style_res = """<meta charset="UTF-8"><style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {View on GitHub (pinned to 4fe4bde114)
Solutions
- Ensure the array passed for cell bbox drawing is np.ndarray with shape (N, 4) or (N, 8).
- If your detector emits (N, 5) with scores, slice them off: bboxes = arr[:, :4].
- Check upstream post-processing (e.g. output bbox decoder) hasn't been replaced or reordered.
Example fix
# before drawed = table_rec.visualize(img_path, raw_pred[:, :5]) # score column kept # after bboxes = raw_pred[:, :4] if raw_pred.shape[1] > 4 else raw_pred drawed = table_rec.visualize(img_path, bboxes)
Defensive patterns
Strategy: validation
Validate before calling
import numpy as np
bboxes = np.asarray(table_cell_bboxes)
if bboxes.ndim != 2 or bboxes.shape[1] not in (4, 8):
raise ValueError(f"expected (N,4) or (N,8) bboxes, got {bboxes.shape}") Type guard
def is_valid_bboxes(arr) -> bool:
arr = np.asarray(arr)
return arr.ndim == 2 and arr.shape[1] in (4, 8) Prevention
- Slice score columns off detector outputs before visualization
- Keep post-processing output contract documented as (N,4)/(N,8)
- Add shape asserts in unit tests of post-processing
When it happens
Trigger: Calling the draw/save-visualization API of the table model with predicted cell boxes shaped (N, 5) (e.g. boxes with confidence appended), (N, 6), or feeding raw model output without post-processing to box format; also (0,) shaped arrays from an empty prediction reshaped incorrectly.
Common situations: Custom post-processing that appends a score column to each bbox; passing logic_points (4-point logical indices) where pixel bboxes were expected; passing a transposed or flattened array.
Related errors
- Invalid scale {scale}, must be positive.
- Input image ({w}, {h}) smaller than the target size ({cw}, {
- {model_path} does not exists.
- {model_path} is not a file.
- Input must be a pillow object or a numpy array.
AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14).
Data as JSON: /api/errors/fcf392dae207d6b3.
Report an issue: GitHub.