PaddlePaddle/PaddleOCR · error · ValueError
'size' must be a list or tuple of two numbers, but got {size
Error message
'size' must be a list or tuple of two numbers, but got {size} What it means
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.
Source
Thrown at ppocr/data/imaug/iaa_augment.py:140
cls = getattr(A, augmenter_type_mapped)
return cls(
**{
k: self.to_tuple_if_list(v)
for k, v in augmenter_args_mapped.items()
}
)
else:
raise RuntimeError("Unknown augmenter arg: " + str(args))
# Map arguments to expected format for each augmenter type
def map_arguments(self, augmenter_type, augmenter_args):
augmenter_args = augmenter_args.copy() # Avoid modifying the original arguments
if augmenter_type == "Resize":
# Ensure size is a valid 2-element list or tuple
size = augmenter_args.get("size")
if size:
if not isinstance(size, (list, tuple)) or len(size) != 2:
raise ValueError(
f"'size' must be a list or tuple of two numbers, but got {size}"
)
min_scale, max_scale = size
return {
"scale_range": (min_scale, max_scale),
"interpolation": 1, # Linear interpolation
"p": 1.0,
}
else:
return {"scale_range": (1.0, 1.0), "interpolation": 1, "p": 1.0}
elif augmenter_type == "Affine":
# Map rotation to a tuple and ensure p=1.0 to apply transformation
rotate = augmenter_args.get("rotate", 0)
if isinstance(rotate, list):
rotate = tuple(rotate)
elif isinstance(rotate, (int, float)):
rotate = (float(rotate), float(rotate))
augmenter_args["rotate"] = rotateView on GitHub (pinned to 2661c7c0ef)
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
Example fix
# before
- { type: Resize, args: { size: 640 } }
# after
- { type: Resize, args: { size: [1.0, 1.0] } } Defensive patterns
Strategy: validation
Validate before calling
for entry in augmenter_args:
if entry['type'] == 'Resize':
size = entry.get('args', {}).get('size')
if size is not None and (not isinstance(size, (list, tuple)) or len(size) != 2):
raise SystemExit(f'Resize size must be [min_scale, max_scale], got {size}') Type guard
def is_valid_iaa_resize_size(size):
import numbers
return size is None or (
isinstance(size, (list, tuple)) and len(size) == 2
and all(isinstance(x, numbers.Number) for x in size)
) Try / catch
try:
aug = IaaAugment(augmenter_args=augmenter_args)
except ValueError as e:
raise ValueError(f'Invalid iaa Resize args: {e}') from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unknown augmenter arg: {}
- OCR pipeline config text must decode to an object.
- OCR pipeline config must be an object or YAML text.
- ${modulePath}.model_dir must be null or an asset descriptor
- Unsupported pipeline_name "${pipelineName}". PaddleOCR.js cu
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/87682c74ced710f7.
Report an issue: GitHub.