PaddlePaddle/PaddleOCR · error · ValueError
translation values should be between 0 and 1
Error message
translation values should be between 0 and 1
What it means
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.
Source
Thrown at ppocr/data/imaug/abinet_aug.py:98
flags = get_interpolation()
return cv2.warpAffine(
img, M, (dst_w, dst_h), flags=flags, borderMode=cv2.BORDER_REPLICATE
)
class CVRandomAffine(object):
def __init__(self, degrees, translate=None, scale=None, shear=None):
assert isinstance(degrees, numbers.Number), "degree should be a single number."
assert degrees >= 0, "degree must be positive."
self.degrees = degrees
if translate is not None:
assert (
isinstance(translate, (tuple, list)) and len(translate) == 2
), "translate should be a list or tuple and it must be of length 2."
for t in translate:
if not (0.0 <= t <= 1.0):
raise ValueError("translation values should be between 0 and 1")
self.translate = translate
if scale is not None:
assert (
isinstance(scale, (tuple, list)) and len(scale) == 2
), "scale should be a list or tuple and it must be of length 2."
for s in scale:
if s <= 0:
raise ValueError("scale values should be positive")
self.scale = scale
if shear is not None:
if isinstance(shear, numbers.Number):
if shear < 0:
raise ValueError(
"If shear is a single number, it must be positive."
)
self.shear = [shear]View on GitHub (pinned to 2661c7c0ef)
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.
Example fix
# before CVRandomAffine(degrees=10, translate=(20, 30)) # ValueError # after CVRandomAffine(degrees=10, translate=(20/img_w, 30/img_h)) # fractions in [0,1]
Defensive patterns
Strategy: validation
Validate before calling
def valid_translate(t) -> bool:
return (t is None
or (isinstance(t, (tuple, list)) and len(t) == 2
and all(isinstance(x, (int, float)) and 0.0 <= x <= 1.0 for x in t))) Type guard
def is_valid_translate(v) -> bool:
return v is None or (isinstance(v, (tuple, list)) and len(v) == 2 and all(0.0 <= x <= 1.0 for x in v)) Prevention
- 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
When it happens
Trigger: 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.
Common situations: Porting torchvision affine configs but entering pixel offsets instead of fractions; typos/negatives in augmentation YAML; assuming larger-than-1 means 'more pixels'.
Related errors
- scale values should be positive
- If shear is a single number, it must be positive.
- Shear should be a single value or a tuple/list containing tw
- Unsupported format: .{ext}\nSupported formats: {supported}
- Invalid mode {mode}, must be one of ['union', 'small', 'larg
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/c1d9c5c546dd66d7.
Report an issue: GitHub.