{"record":{"id":"590ce5236b868db7","repo":"PaddlePaddle/PaddleOCR","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":"ppocr/data/imaug/unimernet_aug.py","lineNumber":528,"sourceCode":"            channels = len(img.getbands())\n        else:\n            channels = img.channels\n        width, height = img.size\n        return [channels, height, width]\n\n    def _compute_resized_output_size(self, image_size, size, max_size=None):\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(self, img, size):\n        _, image_height, image_width = self.get_dimensions(img)\n        if isinstance(size, int):\n            size = [size]\n        max_size = None\n        output_size = self._compute_resized_output_size(\n            (image_height, image_width), size, max_size","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/data/imaug/unimernet_aug.py#L510-L546","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Raise max_size above the short-edge size, e.g. size: 768 with max_size: 1024","Or lower the requested size so size < max_size, e.g. size: 640 with max_size: 768","Drop max_size (pass None) if no upper bound is needed","Add a guard in custom code: assert max_size is None or max_size > min(size)"],"exampleFix":"# before\nresize(img, size=[960], max_size=960)\n# after\nresize(img, size=[960], max_size=1280)","handlingStrategy":"validation","validationCode":"if max_size is not None and len(size) == 1 and max_size <= size[0]:\n    raise SystemExit(f'max_size ({max_size}) must be > short-edge size ({size[0]})')","typeGuard":"def is_valid_resize_args(size, max_size) -> bool:\n    short = size if isinstance(size, int) else size[0]\n    return max_size is None or len(size) > 1 or max_size > short","tryCatchPattern":"try:\n    out = t.resize(img, size=size, max_size=max_size)\nexcept ValueError as e:\n    if 'strictly greater' in str(e):\n        out = t.resize(img, size=size, max_size=max(size[0] + 1, max_size))\n    else:\n        raise","preventionTips":["Enforce size < max_size wherever resize parameters are defined or sampled","Keep the invariant in one helper used by all resize configs","When tuning for memory, lower size instead of max_size"],"tags":["resize","unimernet","argument-validation","preprocessing"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}