{"record":{"id":"87682c74ced710f7","repo":"PaddlePaddle/PaddleOCR","slug":"size-must-be-a-list-or-tuple-of-two-numbers-but","errorCode":null,"errorMessage":"'size' must be a list or tuple of two numbers, but got {size}","messagePattern":"'size' must be a list or tuple of two numbers, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/data/imaug/iaa_augment.py","lineNumber":140,"sourceCode":"                cls = getattr(A, augmenter_type_mapped)\n                return cls(\n                    **{\n                        k: self.to_tuple_if_list(v)\n                        for k, v in augmenter_args_mapped.items()\n                    }\n                )\n        else:\n            raise RuntimeError(\"Unknown augmenter arg: \" + str(args))\n\n    # Map arguments to expected format for each augmenter type\n    def map_arguments(self, augmenter_type, augmenter_args):\n        augmenter_args = augmenter_args.copy()  # Avoid modifying the original arguments\n        if augmenter_type == \"Resize\":\n            # Ensure size is a valid 2-element list or tuple\n            size = augmenter_args.get(\"size\")\n            if size:\n                if not isinstance(size, (list, tuple)) or len(size) != 2:\n                    raise ValueError(\n                        f\"'size' must be a list or tuple of two numbers, but got {size}\"\n                    )\n                min_scale, max_scale = size\n                return {\n                    \"scale_range\": (min_scale, max_scale),\n                    \"interpolation\": 1,  # Linear interpolation\n                    \"p\": 1.0,\n                }\n            else:\n                return {\"scale_range\": (1.0, 1.0), \"interpolation\": 1, \"p\": 1.0}\n        elif augmenter_type == \"Affine\":\n            # Map rotation to a tuple and ensure p=1.0 to apply transformation\n            rotate = augmenter_args.get(\"rotate\", 0)\n            if isinstance(rotate, list):\n                rotate = tuple(rotate)\n            elif isinstance(rotate, (int, float)):\n                rotate = (float(rotate), float(rotate))\n            augmenter_args[\"rotate\"] = rotate","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/data/imaug/iaa_augment.py#L122-L158","documentation":"When the IAA augmenter type is 'Resize', PaddleOCR maps the imgaug-style 'size' argument to its internal scale_range format. The mapping requires 'size' to be a list or tuple of exactly two numbers; anything else (scalar, string, 3-element list) raises ValueError with the offending value embedded in the message.","triggerScenarios":"Adding { type: Resize, args: { size: 640 } } or { type: Resize, args: { size: [640, 640, 3] } } to the augmenter_args list in a training config using IaaAugment.","commonSituations":"Writing imgaug-style configs where size is a single int (valid for some imgaug classes but not this mapper); copying an image shape [h, w, c] instead of a scale pair; note the two numbers are interpreted as min_scale/max_scale (fractions), so [640, 640] means a 640x scale, not pixels.","solutions":["Give size as a two-number list or tuple, e.g. size: [1.0, 1.0] for no scaling","Understand the semantics: the values are scale factors, so use e.g. size: [0.8, 1.2] for 80-120% scaling","Omit size entirely to get the default no-scale mapping {scale_range: (1.0, 1.0)}","Validate the config programmatically before training: assert isinstance(size, (list, tuple)) and len(size) == 2"],"exampleFix":"# before\n- { type: Resize, args: { size: 640 } }\n# after\n- { type: Resize, args: { size: [1.0, 1.0] } }","handlingStrategy":"validation","validationCode":"for entry in augmenter_args:\n    if entry['type'] == 'Resize':\n        size = entry.get('args', {}).get('size')\n        if size is not None and (not isinstance(size, (list, tuple)) or len(size) != 2):\n            raise SystemExit(f'Resize size must be [min_scale, max_scale], got {size}')","typeGuard":"def is_valid_iaa_resize_size(size):\n    import numbers\n    return size is None or (\n        isinstance(size, (list, tuple)) and len(size) == 2\n        and all(isinstance(x, numbers.Number) for x in size)\n    )","tryCatchPattern":"try:\n    aug = IaaAugment(augmenter_args=augmenter_args)\nexcept ValueError as e:\n    raise ValueError(f'Invalid iaa Resize args: {e}') from e","preventionTips":["Remember size here means (min_scale, max_scale) fractions, not pixels","Use [1.0, 1.0] for no-op resize","Keep augmenter args in code rather than YAML when exploring, so types are checked by your IDE"],"tags":["config","imgaug","augmentation","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}