opendatalab/MinerU · error · ValueError
Input image ({w}, {h}) smaller than the target size ({cw}, {
Error message
Input image ({w}, {h}) smaller than the target size ({cw}, {ch}). What it means
The table-orientation classifier resizes the short edge to 256 then center-crops 224x224; after that resize both dimensions should be >= 224, so this guard fires only for degenerate inputs (near-zero-size images where scaling cannot produce a valid crop, or rounding on extreme aspect ratios). It protects the downstream slice from producing an empty tensor.
Source
Thrown at mineru/model/table/cls/paddle_table_cls.py:43
self.mean = [0.485, 0.456, 0.406]
self.labels = [AtomicModel.WiredTable, AtomicModel.WirelessTable]
def preprocess(self, input_img):
# 放大图片,使其最短边长为256
h, w = input_img.shape[:2]
scale = 256 / min(h, w)
h_resize = round(h * scale)
w_resize = round(w * scale)
img = cv2.resize(input_img, (w_resize, h_resize), interpolation=1)
# 调整为224*224的正方形
h, w = img.shape[:2]
cw, ch = 224, 224
x1 = max(0, (w - cw) // 2)
y1 = max(0, (h - ch) // 2)
x2 = min(w, x1 + cw)
y2 = min(h, y1 + ch)
if w < cw or h < ch:
raise ValueError(
f"Input image ({w}, {h}) smaller than the target size ({cw}, {ch})."
)
img = img[y1:y2, x1:x2, ...]
# 正则化
split_im = list(cv2.split(img))
std = [0.229, 0.224, 0.225]
scale = 0.00392156862745098
mean = [0.485, 0.456, 0.406]
alpha = [scale / std[i] for i in range(len(std))]
beta = [-mean[i] / std[i] for i in range(len(std))]
for c in range(img.shape[2]):
split_im[c] = split_im[c].astype(np.float32)
split_im[c] *= alpha[c]
split_im[c] += beta[c]
img = cv2.merge(split_im)
# 5. 转换为 CHW 格式
img = img.transpose((2, 0, 1))
imgs = [img]View on GitHub (pinned to 4fe4bde114)
Solutions
- Validate the crop size upstream: skip regions with w < 10 or h < 10 before classification.
- Check the layout detection boxes for zero/negative area and clamp them.
- If tiny tables must be classified, upscale with a stronger interpolation before this transform.
Example fix
# before
cls_result = table_cls.predict(crop) # crop may be 5x5
# after
if min(crop.shape[:2]) < 24:
continue # skip degenerate crop
cls_result = table_cls.predict(crop) Defensive patterns
Strategy: validation
Validate before calling
h, w = crop.shape[:2]
if min(h, w) < 24:
skip = True # degenerate crop; do not classify Type guard
def is_classifiable_crop(img: np.ndarray) -> bool:
return img.ndim >= 2 and min(img.shape[:2]) >= 24 Try / catch
try:
res = table_cls(img)
except ValueError as e:
if 'smaller than the target size' in str(e):
return default_orientation() # skip/assume no rotation
raise Prevention
- Filter zero/negative-area layout boxes before cropping.
- Skip or pad crops below ~24px on the short edge.
- Log skipped-region stats to detect upstream detector regressions.
When it happens
Trigger: Calling the cls transform with an image whose min(h, w) is 0 or 1 (blank crop, failed region extraction), producing a resized dimension below 224 after integer rounding.
Common situations: Empty table-region crops from an upstream layout detector with bad boxes (negative or zero-area), fully transparent/blank page regions rendered at tiny size.
Related errors
- The channel({channel}) of the img is not in [1, 2, 3, 4]
- backend: {backend} is not supported for resize.Supported bac
- Unsupported image shape for UnimerSwinImageProcessor: {image
- The img type {type(img)} does not in {InputType.__args__}
- cannot identify image file {img}
AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14).
Data as JSON: /api/errors/424c78a98184420d.
Report an issue: GitHub.