PaddlePaddle/PaddleOCR · error · ValueError

max_size = {max_size} must be strictly greater than the requ

Error message

max_size = {max_size} must be strictly greater than the requested size for the smaller edge size = {size}

What it means

This is torchvision-style resize logic vendored for UniMERNet formula recognition. When you resize by shorter-edge size with a max_size bound, the code requires max_size to be STRICTLY greater than the requested short edge; otherwise the constraints are contradictory and it raises ValueError showing both values.

Source

Thrown at ppocr/data/imaug/unimernet_aug.py:528

            channels = len(img.getbands())
        else:
            channels = img.channels
        width, height = img.size
        return [channels, height, width]

    def _compute_resized_output_size(self, image_size, size, max_size=None):
        if len(size) == 1:  # specified size only for the smallest edge
            h, w = image_size
            short, long = (w, h) if w <= h else (h, w)
            requested_new_short = size if isinstance(size, int) else size[0]

            new_short, new_long = requested_new_short, int(
                requested_new_short * long / short
            )

            if max_size is not None:
                if max_size <= requested_new_short:
                    raise ValueError(
                        f"max_size = {max_size} must be strictly greater than the requested "
                        f"size for the smaller edge size = {size}"
                    )
                if new_long > max_size:
                    new_short, new_long = int(max_size * new_short / new_long), max_size

            new_w, new_h = (new_short, new_long) if w <= h else (new_long, new_short)
        else:  # specified both h and w
            new_w, new_h = size[1], size[0]
        return [new_h, new_w]

    def resize(self, img, size):
        _, image_height, image_width = self.get_dimensions(img)
        if isinstance(size, int):
            size = [size]
        max_size = None
        output_size = self._compute_resized_output_size(
            (image_height, image_width), size, max_size

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Raise max_size above the short-edge size, e.g. size: 768 with max_size: 1024
  2. Or lower the requested size so size < max_size, e.g. size: 640 with max_size: 768
  3. Drop max_size (pass None) if no upper bound is needed
  4. Add a guard in custom code: assert max_size is None or max_size > min(size)

Example fix

# before
resize(img, size=[960], max_size=960)
# after
resize(img, size=[960], max_size=1280)
Defensive patterns

Strategy: validation

Validate before calling

if max_size is not None and len(size) == 1 and max_size <= size[0]:
    raise SystemExit(f'max_size ({max_size}) must be > short-edge size ({size[0]})')

Type guard

def is_valid_resize_args(size, max_size) -> bool:
    short = size if isinstance(size, int) else size[0]
    return max_size is None or len(size) > 1 or max_size > short

Try / catch

try:
    out = t.resize(img, size=size, max_size=max_size)
except ValueError as e:
    if 'strictly greater' in str(e):
        out = t.resize(img, size=size, max_size=max(size[0] + 1, max_size))
    else:
        raise

Prevention

When it happens

Trigger: Calling resize with size=[shorter_edge] (or an int) together with max_size where max_size <= size, e.g. size=800, max_size=800 or size=[960], max_size=768.

Common situations: Tuning UniMERNet/unimernet_aug configs for VRAM constraints and lowering max_size below the short edge; hand-writing a Resize op and assuming max_size is inclusive (torchvision requires strictly greater too); mixing up the argument order when calling resize(img, size, max_size).

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/590ce5236b868db7. Report an issue: GitHub.