{"record":{"id":"c1d9c5c546dd66d7","repo":"PaddlePaddle/PaddleOCR","slug":"translation-values-should-be-between-0-and-1","errorCode":null,"errorMessage":"translation values should be between 0 and 1","messagePattern":"translation values should be between 0 and 1","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/data/imaug/abinet_aug.py","lineNumber":98,"sourceCode":"        flags = get_interpolation()\n        return cv2.warpAffine(\n            img, M, (dst_w, dst_h), flags=flags, borderMode=cv2.BORDER_REPLICATE\n        )\n\n\nclass CVRandomAffine(object):\n    def __init__(self, degrees, translate=None, scale=None, shear=None):\n        assert isinstance(degrees, numbers.Number), \"degree should be a single number.\"\n        assert degrees >= 0, \"degree must be positive.\"\n        self.degrees = degrees\n\n        if translate is not None:\n            assert (\n                isinstance(translate, (tuple, list)) and len(translate) == 2\n            ), \"translate should be a list or tuple and it must be of length 2.\"\n            for t in translate:\n                if not (0.0 <= t <= 1.0):\n                    raise ValueError(\"translation values should be between 0 and 1\")\n        self.translate = translate\n\n        if scale is not None:\n            assert (\n                isinstance(scale, (tuple, list)) and len(scale) == 2\n            ), \"scale should be a list or tuple and it must be of length 2.\"\n            for s in scale:\n                if s <= 0:\n                    raise ValueError(\"scale values should be positive\")\n        self.scale = scale\n\n        if shear is not None:\n            if isinstance(shear, numbers.Number):\n                if shear < 0:\n                    raise ValueError(\n                        \"If shear is a single number, it must be positive.\"\n                    )\n                self.shear = [shear]","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/data/imaug/abinet_aug.py#L80-L116","documentation":"CVRandomAffine's constructor validates the translate argument: it must be a 2-element tuple/list where every element t satisfies 0.0 <= t <= 1.0 (fractions of image size, mirroring torchvision semantics). Any value outside [0,1] raises ValueError during transform construction.","triggerScenarios":"CVRandomAffine(degrees=10, translate=(0.1, 1.5)) or translate=(-0.1, 0.2) — an element outside [0.0, 1.0]; values supplied as pixel counts (e.g. translate=(20, 30)) also trigger it.","commonSituations":"Porting torchvision affine configs but entering pixel offsets instead of fractions; typos/negatives in augmentation YAML; assuming larger-than-1 means 'more pixels'.","solutions":["Express translation as fractions of image dimensions within [0,1], e.g. translate=(0.1, 0.2).","If you need pixel units, divide by image size first.","Validate the config values before building transforms."],"exampleFix":"# before\nCVRandomAffine(degrees=10, translate=(20, 30))  # ValueError\n# after\nCVRandomAffine(degrees=10, translate=(20/img_w, 30/img_h))  # fractions in [0,1]","handlingStrategy":"validation","validationCode":"def valid_translate(t) -> bool:\n    return (t is None\n            or (isinstance(t, (tuple, list)) and len(t) == 2\n                and all(isinstance(x, (int, float)) and 0.0 <= x <= 1.0 for x in t)))","typeGuard":"def is_valid_translate(v) -> bool:\n    return v is None or (isinstance(v, (tuple, list)) and len(v) == 2 and all(0.0 <= x <= 1.0 for x in v))","tryCatchPattern":null,"preventionTips":["Think fractions-of-image-size, never pixels, for translate","Add a schema check on augmentation config before dataset build","Reject negatives at config-parse time with a clear message"],"tags":["data-augmentation","abinet","affine","validation","valueerror"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}