{"record":{"id":"ab1a427e190b6312","repo":"PaddlePaddle/PaddleOCR","slug":"factor-must-be-number-or-list-with-length-2","errorCode":null,"errorMessage":"factor must be number or list with length 2","messagePattern":"factor must be number or list with length 2","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ppocr/data/imaug/abinet_aug.py","lineNumber":281,"sourceCode":"        )\n        img = img[min_y:, min_x:]\n        return img\n\n\nclass CVRescale(object):\n    def __init__(self, factor=4, base_size=(128, 512)):\n        \"\"\"Define image scales using gaussian pyramid and rescale image to target scale.\n\n        Args:\n            factor: the decayed factor from base size, factor=4 keeps target scale by default.\n            base_size: base size the build the bottom layer of pyramid\n        \"\"\"\n        if isinstance(factor, numbers.Number):\n            self.factor = round(sample_uniform(0, factor))\n        elif isinstance(factor, (tuple, list)) and len(factor) == 2:\n            self.factor = round(sample_uniform(factor[0], factor[1]))\n        else:\n            raise Exception(\"factor must be number or list with length 2\")\n        # assert factor is valid\n        self.base_h, self.base_w = base_size[:2]\n\n    def __call__(self, img):\n        if self.factor == 0:\n            return img\n        src_h, src_w = img.shape[:2]\n        cur_w, cur_h = self.base_w, self.base_h\n        scale_img = cv2.resize(img, (cur_w, cur_h), interpolation=get_interpolation())\n        for _ in range(self.factor):\n            scale_img = cv2.pyrDown(scale_img)\n        scale_img = cv2.resize(\n            scale_img, (src_w, src_h), interpolation=get_interpolation()\n        )\n        return scale_img\n\n\nclass CVGaussianNoise(object):","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/data/imaug/abinet_aug.py#L263-L299","documentation":"CVImagePyramid's constructor (ppocr/data/imaug/abinet_aug.py) accepts factor as either a number (sample uniformly in [0, factor]) or a 2-element tuple/list (sample uniformly in that range); anything else raises a bare Exception('factor must be number or list with length 2'). This controls how many gaussian-pyramid downscalings are applied for ABINet training crops.","triggerScenarios":"CVImagePyramid(factor='4'), factor=[1, 2, 3] (length 3), factor={'min':1,'max':4}, or a 1-element list.","commonSituations":"YAML configs parsing numbers as strings ('4' stays a str); over-specified config dicts; expecting torchvision-style (min, max) plus extra keys.","solutions":["Pass an int/float (e.g. factor=4) or an exact 2-element list/tuple like factor=(2, 5).","If loading from YAML/JSON, cast: factor=int(cfg['factor']) when it is a single value.","Validate length == 2 for range forms before constructing the transform."],"exampleFix":"# before\nCVImagePyramid(factor=str(cfg['factor']))  # Exception: factor must be number or list with length 2\n# after\nraw = cfg['factor']\nfactor = int(raw) if isinstance(raw, (int, float)) else tuple(raw[:2])\nCVImagePyramid(factor=factor)","handlingStrategy":"validation","validationCode":"import numbers\n\ndef valid_factor(f) -> bool:\n    return (isinstance(f, numbers.Number)\n            or (isinstance(f, (tuple, list)) and len(f) == 2))","typeGuard":"import numbers\n\ndef is_valid_factor(v) -> bool:\n    return isinstance(v, numbers.Number) or (isinstance(v, (tuple, list)) and len(v) == 2)","tryCatchPattern":null,"preventionTips":["Cast YAML scalar strings to int before passing factor","Keep range specs to exactly (low, high)","Validate transform args once at config load, not per sample"],"tags":["data-augmentation","abinet","pyramid","config","exception"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}