{"record":{"id":"c4dee1fe61987e7c","repo":"PaddlePaddle/PaddleOCR","slug":"type-of-target-size-is-invalid-now-is","errorCode":null,"errorMessage":"Type of target_size is invalid. Now is {}","messagePattern":"Type of target_size is invalid\\. Now is (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ppocr/data/imaug/operators.py","lineNumber":140,"sourceCode":"        data[\"fast_label\"] = fast_label\n        return data\n\n\nclass KeepKeys(object):\n    def __init__(self, keep_keys, **kwargs):\n        self.keep_keys = keep_keys\n\n    def __call__(self, data):\n        data_list = []\n        for key in self.keep_keys:\n            data_list.append(data[key])\n        return data_list\n\n\nclass Pad(object):\n    def __init__(self, size=None, size_div=32, **kwargs):\n        if size is not None and not isinstance(size, (int, list, tuple)):\n            raise TypeError(\n                \"Type of target_size is invalid. Now is {}\".format(type(size))\n            )\n        if isinstance(size, int):\n            size = [size, size]\n        self.size = size\n        self.size_div = size_div\n\n    def __call__(self, data):\n        img = data[\"image\"]\n        img_h, img_w = img.shape[0], img.shape[1]\n        if self.size:\n            resize_h2, resize_w2 = self.size\n            assert (\n                img_h < resize_h2 and img_w < resize_w2\n            ), \"(h, w) of target size should be greater than (img_h, img_w)\"\n        else:\n            resize_h2 = max(\n                int(math.ceil(img.shape[0] / self.size_div) * self.size_div),","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/data/imaug/operators.py#L122-L158","documentation":"Pad is a preprocessing op that pads images to a fixed size or to a multiple of size_div (default 32). Its constructor validates that 'size', when given, is an int, list, or tuple; any other type raises TypeError with the actual type printed.","triggerScenarios":"Adding a Pad op to a yml preprocess pipeline with size given as a string (size: '640'), a dict, or a numpy array.","commonSituations":"YAML quoting mistakes that turn 640 into '640'; passing a numpy int64 or np.array from custom code (numpy scalar is not a numbers-compatible int for this isinstance check unless converted); copy-pasting padding configs between ops with different signatures.","solutions":["Use an int (size: 640 means [640, 640]) or a two-element list (size: [640, 640])","Remove quoting in YAML so the value parses as a number","Convert numpy values in Python code: size=int(np_val) or size=np_val.tolist()","Omit size entirely to pad only to the size_div multiple"],"exampleFix":"# before\n- Pad:\n    size: '640'\n# after\n- Pad:\n    size: [640, 640]","handlingStrategy":"type-guard","validationCode":"s = op_cfg.get('size')\nif s is not None and not isinstance(s, (int, list, tuple)):\n    raise SystemExit(f'Pad size must be int or [h, w], got {type(s).__name__}')","typeGuard":"import numbers\ndef is_valid_pad_size(s):\n    return s is None or isinstance(s, int) or (\n        isinstance(s, (list, tuple)) and len(s) == 2\n        and all(isinstance(x, numbers.Number) for x in s)\n    )","tryCatchPattern":"try:\n    pad = Pad(**op_cfg)\nexcept TypeError as e:\n    raise ValueError(f'Invalid Pad config {op_cfg}: {e}') from e","preventionTips":["Avoid YAML quoting around numeric fields","Convert numpy scalars with int() before passing into op configs","Add a config-lint pass over all preprocess op params before training"],"tags":["config","preprocessing","type-validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}