opendatalab/MinerU · 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

Thrown by PP-FormulaNet-Plus's image preprocessor when resizing so that only the smaller edge is specified (single-int size). The processor computes the new long edge from the aspect ratio and clamps it with max_size; that clamp is only valid when max_size is strictly greater than the requested short edge, otherwise the invariant of the resize (short edge == requested size) cannot hold. This mirrors torchvision's resize semantics.

Source

Thrown at mineru/model/mfr/pp_formulanet_plus_m/processors.py:95

        Args:
            image_size (tuple): The original size of the image (height, width).
            size (int or tuple): The desired size for the smallest edge or both height and width.
            max_size (int, optional): The maximum allowed size for the longer edge.

        Returns:
            list: A list containing the new height and width."""
        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: Image.Image, size: Union[int, Tuple[int, int]]
    ) -> Image.Image:
        """Resizes the image to the specified size.

        Args:
            img (PIL.Image.Image): The input image.

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Set max_size strictly greater than the requested short-edge size (e.g. size=384, max_size>=385, commonly size*1.1 or None).
  2. Pass max_size=None if no long-edge cap is needed.
  3. Pass size as a (h, w) tuple to take the both-dimensions branch, which ignores max_size.
  4. If the value comes from a config file, fix the config rather than catching the exception.

Example fix

# before
outputs = processor(images=img, size=384, max_size=384)

# after
outputs = processor(images=img, size=384, max_size=None)
# or
outputs = processor(images=img, size=(384, 384))
Defensive patterns

Strategy: validation

Validate before calling

def check_resize_args(size, max_size):
    if isinstance(size, int) or len(size) == 1:
        short = size if isinstance(size, int) else size[0]
        if max_size is not None and max_size <= short:
            raise ValueError(f'max_size={max_size} must be > short-edge size={short}')

Type guard

def is_valid_size_pair(size, max_size) -> bool:
    if isinstance(size, (tuple, list)) and len(size) == 2:
        return True
    short = size if isinstance(size, int) else size[0]
    return max_size is None or max_size > short

Try / catch

try:
    processor(images=img, size=size, max_size=max_size)
except ValueError as e:
    if 'must be strictly greater' in str(e):
        outputs = processor(images=img, size=size, max_size=None)  # retry without cap
    else:
        raise

Prevention

When it happens

Trigger: Calling the processor's resize/get_size logic with size as a single int (e.g. size=384) while also passing max_size that is <= size (e.g. max_size=384 or max_size=256). Only the len(size)==1 branch raises; passing (h, w) skips the check entirely.

Common situations: Reusing config values originally tuned for another model (max_size copied as the same value as size), tightening max_size to cap memory on large formula crops, or porting torchvision-style presets where max_size equals the target edge.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/13631385de08b65a. Report an issue: GitHub.