opendatalab/MinerU · error · ValueError
Invalid scale {scale}, must be positive.
Error message
Invalid scale {scale}, must be positive. What it means
Raised by rescale_size() (mmcv-derived helper inside mineru's UNet table recognizer) when the scale argument is a numeric value that is zero or negative. The function multiplies both image edges by this factor, so a non-positive factor is mathematically meaningless and would produce a zero-size image. It exists to fail fast before cv2/NumPy produce a cryptic downstream error.
Source
Thrown at mineru/model/table/rec/unet_table/utils.py:317
def rescale_size(old_size, scale, return_scale=False):
"""Calculate the new size to be rescaled to.
Args:
old_size (tuple[int]): The old size (w, h) of image.
scale (float | tuple[int]): The scaling factor or maximum size.
If it is a float number, then the image will be rescaled by this
factor, else if it is a tuple of 2 integers, then the image will
be rescaled as large as possible within the scale.
return_scale (bool): Whether to return the scaling factor besides the
rescaled image size.
Returns:
tuple[int]: The new rescaled image size.
"""
w, h = old_size
if isinstance(scale, (float, int)):
if scale <= 0:
raise ValueError(f"Invalid scale {scale}, must be positive.")
scale_factor = scale
elif isinstance(scale, tuple):
max_long_edge = max(scale)
max_short_edge = min(scale)
scale_factor = min(max_long_edge / max(h, w), max_short_edge / min(h, w))
else:
raise TypeError(
f"Scale must be a number or tuple of int, but got {type(scale)}"
)
new_size = _scale_size((w, h), scale_factor)
if return_scale:
return new_size, scale_factor
else:
return new_size
View on GitHub (pinned to 4fe4bde114)
Solutions
- Check the scale value passed to the table preprocessing config; it must be a positive float/int or a tuple like (736, 1280).
- If scale is computed dynamically, guard the denominator: scale = target / max(max(h, w), 1).
- Print/inspect the input image size right before the call; a (0, 0) size usually means the image failed to load earlier.
- If you intended a max-size constraint, pass the tuple form (short_edge, long_edge) instead of a single factor.
Example fix
// before
new_size = rescale_size(old_size, 0) # scale typo / computed as 0
// after
new_size = rescale_size(old_size, (736, 1280)) # tuple form, or a positive factor
if isinstance(scale, (int, float)) and scale <= 0:
raise ValueError(f"bad scale config: {scale}") Defensive patterns
Strategy: validation
Validate before calling
def safe_scale(scale):
if isinstance(scale, (int, float)) and scale <= 0:
raise ValueError(f"scale must be positive, got {scale}")
return scale
new_size = rescale_size(size, safe_scale(cfg_scale)) Type guard
def is_valid_scale(s) -> bool:
return (isinstance(s, (int, float)) and s > 0) or (
isinstance(s, tuple) and len(s) == 2 and all(isinstance(v, int) for v in s)
) Try / catch
try:
new_size = rescale_size(size, scale)
except ValueError as e:
if "must be positive" in str(e):
scale = 1.0
new_size = rescale_size(size, scale)
else:
raise Prevention
- Validate scale factors in config loaders before pipeline startup
- Guard dynamic ratios: divide by max(dim, 1)
- Log the effective scale value once at init
When it happens
Trigger: Calling rescale_size(old_size, scale) (or the table-rec pipeline that calls it, e.g. table structure preprocessing) with scale=0, a negative float, or a value computed from division that underflowed to 0, e.g. scale = target_px / max(h, w) when max(h, w) is huge or target_px is 0.
Common situations: Custom table-detection configs that pass a user-defined scale factor of 0 by mistake; dynamically computed ratios where the denominator is an image whose dimensions were read as 0 (corrupt image or failed load); copy-pasting a config where scale was meant to be a (short, long) tuple but only one element was supplied.
Related errors
- Input image ({w}, {h}) smaller than the target size ({cw}, {
- The channel({channel}) of the img is not in [1, 2, 3, 4]
- backend: {backend} is not supported for resize.Supported bac
- Scale must be a number or tuple of int, but got {type(scale)
- Shape of table bounding boxes is not between in 4 or 8.
AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14).
Data as JSON: /api/errors/a45cfd4646dde288.
Report an issue: GitHub.