{"record":{"id":"13631385de08b65a","repo":"opendatalab/MinerU","slug":"max-size-max-size-must-be-strictly-greater-tha","errorCode":null,"errorMessage":"max_size = {max_size} must be strictly greater than the requested size for the smaller edge size = {size}","messagePattern":"max_size = (.+?) must be strictly greater than the requested size for the smaller edge size = (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mineru/model/mfr/pp_formulanet_plus_m/processors.py","lineNumber":95,"sourceCode":"        Args:\n            image_size (tuple): The original size of the image (height, width).\n            size (int or tuple): The desired size for the smallest edge or both height and width.\n            max_size (int, optional): The maximum allowed size for the longer edge.\n\n        Returns:\n            list: A list containing the new height and width.\"\"\"\n        if len(size) == 1:  # specified size only for the smallest edge\n            h, w = image_size\n            short, long = (w, h) if w <= h else (h, w)\n            requested_new_short = size if isinstance(size, int) else size[0]\n\n            new_short, new_long = requested_new_short, int(\n                requested_new_short * long / short\n            )\n\n            if max_size is not None:\n                if max_size <= requested_new_short:\n                    raise ValueError(\n                        f\"max_size = {max_size} must be strictly greater than the requested \"\n                        f\"size for the smaller edge size = {size}\"\n                    )\n                if new_long > max_size:\n                    new_short, new_long = int(max_size * new_short / new_long), max_size\n\n            new_w, new_h = (new_short, new_long) if w <= h else (new_long, new_short)\n        else:  # specified both h and w\n            new_w, new_h = size[1], size[0]\n        return [new_h, new_w]\n\n    def resize(\n            self, img: Image.Image, size: Union[int, Tuple[int, int]]\n    ) -> Image.Image:\n        \"\"\"Resizes the image to the specified size.\n\n        Args:\n            img (PIL.Image.Image): The input image.","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/mfr/pp_formulanet_plus_m/processors.py#L77-L113","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set max_size strictly greater than the requested short-edge size (e.g. size=384, max_size>=385, commonly size*1.1 or None).","Pass max_size=None if no long-edge cap is needed.","Pass size as a (h, w) tuple to take the both-dimensions branch, which ignores max_size.","If the value comes from a config file, fix the config rather than catching the exception."],"exampleFix":"# before\noutputs = processor(images=img, size=384, max_size=384)\n\n# after\noutputs = processor(images=img, size=384, max_size=None)\n# or\noutputs = processor(images=img, size=(384, 384))","handlingStrategy":"validation","validationCode":"def check_resize_args(size, max_size):\n    if isinstance(size, int) or len(size) == 1:\n        short = size if isinstance(size, int) else size[0]\n        if max_size is not None and max_size <= short:\n            raise ValueError(f'max_size={max_size} must be > short-edge size={short}')","typeGuard":"def is_valid_size_pair(size, max_size) -> bool:\n    if isinstance(size, (tuple, list)) and len(size) == 2:\n        return True\n    short = size if isinstance(size, int) else size[0]\n    return max_size is None or max_size > short","tryCatchPattern":"try:\n    processor(images=img, size=size, max_size=max_size)\nexcept ValueError as e:\n    if 'must be strictly greater' in str(e):\n        outputs = processor(images=img, size=size, max_size=None)  # retry without cap\n    else:\n        raise","preventionTips":["Centralize size/max_size in one config constant pair validated at startup.","Prefer (h, w) tuples when exact output dimensions are required.","Add a unit test asserting max_size > size for every preset you ship."],"tags":["image-processing","configuration","formula-recognition"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}