PaddlePaddle/PaddleOCR · error · Exception
radius must be number or list with length 2
Error message
radius must be number or list with length 2
What it means
CVGaussionBlur is the Gaussian-blur augmentation used by ABINet text recognition training in PaddleOCR. Its constructor requires the 'radius' argument to be either a single number (maximum radius, sampled asymmetrically) or a tuple/list of exactly two numbers (a min/max range sampled uniformly). Any other type or length raises this exception before any image is processed.
Source
Thrown at ppocr/data/imaug/abinet_aug.py:339
self.lam = int(sample_uniform(lam[0], lam[1]))
else:
raise Exception("lam must be number or list with length 2")
def __call__(self, img):
noise = np.random.poisson(lam=self.lam, size=img.shape)
img = np.clip(img + noise, 0, 255).astype(np.uint8)
return img
class CVGaussionBlur(object):
def __init__(self, radius):
self.radius = radius
if isinstance(radius, numbers.Number):
self.radius = max(int(sample_asym(radius)), 1)
elif isinstance(radius, (tuple, list)) and len(radius) == 2:
self.radius = int(sample_uniform(radius[0], radius[1]))
else:
raise Exception("radius must be number or list with length 2")
def __call__(self, img):
fil = cv2.getGaussianKernel(ksize=self.radius, sigma=1, ktype=cv2.CV_32F)
img = cv2.sepFilter2D(img, -1, fil, fil)
return img
class CVMotionBlur(object):
def __init__(self, degrees=12, angle=90):
if isinstance(degrees, numbers.Number):
self.degree = max(int(sample_asym(degrees)), 1)
elif isinstance(degrees, (tuple, list)) and len(degrees) == 2:
self.degree = int(sample_uniform(degrees[0], degrees[1]))
else:
raise Exception("degree must be number or list with length 2")
self.angle = sample_uniform(-angle, angle)
def __call__(self, img):View on GitHub (pinned to 2661c7c0ef)
Solutions
- Set radius to a single number, e.g. radius: 2 in the config
- Or set radius to a two-element range, e.g. radius: [1, 3]
- Check for YAML type traps: an unquoted value like radius: 2, 3 parses incorrectly; keep the list bracketed
- If building the pipeline in Python, verify with isinstance(radius, (int, float)) or (isinstance(radius, (list, tuple)) and len(radius) == 2) before constructing
Example fix
# before (config) aug: CVGaussionBlur: radius: [1, 2, 3] # after aug: CVGaussionBlur: radius: [1, 3]
Defensive patterns
Strategy: type-guard
Validate before calling
import numbers
r = cfg['radius']
ok = isinstance(r, numbers.Number) or (isinstance(r, (list, tuple)) and len(r) == 2 and all(isinstance(x, numbers.Number) for x in r))
if not ok:
raise SystemExit('CVGaussionBlur radius must be a number or [min, max]') Type guard
def is_valid_blur_radius(r):
import numbers
return isinstance(r, numbers.Number) or (
isinstance(r, (list, tuple)) and len(r) == 2
and all(isinstance(x, numbers.Number) for x in r)
) Try / catch
try:
aug = CVGaussionBlur(radius=cfg['radius'])
except Exception as e:
raise ValueError(f'Bad blur config: {cfg}; cause: {e}') from e Prevention
- Validate augmentation configs with a schema check before launching training
- Prefer the two-element range form [min, max] consistently across blur ops
- Load and print the parsed YAML once to confirm types (int/list, not str)
When it happens
Trigger: Instantiating CVGaussionBlur from an ABINet yml config (Train.dataset.transforms -> tia or aug entries) with radius given as a string (e.g. '2'), a list of length other than 2 (e.g. [1, 2, 3]), a dict, or None.
Common situations: Editing configs/rec/abinet/abinet_rec.yml or a distilled copy and changing the blur radius to an invalid form; hand-writing an augmenter pipeline in a custom training script; copy-pasting an imgaug-style parameter (which sometimes uses 3-element lists) into this class.
Related errors
- Interpolation types only nearest, linear, cubic, area are su
- factor must be number or list with length 2
- degree must be number or list with length 2
- lam must be number or list with length 2
- translation values should be between 0 and 1
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/ad07fed2c636c05c.
Report an issue: GitHub.