PaddlePaddle/PaddleOCR · error · Exception
Unsupported interpolation type !!!
Error message
Unsupported interpolation type !!!
What it means
This grayscale-recognition image-normalization class accepts only OpenCV interpolation codes 0 (NEAREST), 1 (LINEAR), 2 (CUBIC), and 3 (AREA) passed as plain ints. Any other value raises 'Unsupported interpolation type !!!' at pipeline construction time.
Source
Thrown at ppocr/data/imaug/rec_img_aug.py:364
return data
class RFLRecResizeImg(object):
def __init__(self, image_shape, padding=True, interpolation=1, **kwargs):
self.image_shape = image_shape
self.padding = padding
self.interpolation = interpolation
if self.interpolation == 0:
self.interpolation = cv2.INTER_NEAREST
elif self.interpolation == 1:
self.interpolation = cv2.INTER_LINEAR
elif self.interpolation == 2:
self.interpolation = cv2.INTER_CUBIC
elif self.interpolation == 3:
self.interpolation = cv2.INTER_AREA
else:
raise Exception("Unsupported interpolation type !!!")
def __call__(self, data):
img = data["image"]
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
norm_img, valid_ratio = resize_norm_img(
img, self.image_shape, self.padding, self.interpolation
)
data["image"] = norm_img
data["valid_ratio"] = valid_ratio
if "iluvatar_gpu" in get_device():
data["valid_ratio"] = np.float32(valid_ratio)
return data
class SRNRecResizeImg(object):
def __init__(self, image_shape, num_heads, max_text_length, **kwargs):
self.image_shape = image_shape
self.num_heads = num_headsView on GitHub (pinned to 2661c7c0ef)
Solutions
- Set interpolation to one of 0/1/2/3 in the yml (e.g. interpolation: 1 for LINEAR)
- If you have a cv2 constant in Python, pass int(cv2.INTER_LINEAR) not the flag name string
- For Lanczos-style quality use 2 (CUBIC) as the closest supported option
- Add a startup assertion in custom code: assert op.interpolation in (0, 1, 2, 3)
Example fix
# before interpolation: 4 # after interpolation: 2
Defensive patterns
Strategy: validation
Validate before calling
iv = op_cfg.get('interpolation', 1)
if iv not in (0, 1, 2, 3):
raise SystemExit(f'interpolation must be 0|1|2|3, got {iv!r}') Type guard
def is_valid_interp(v) -> bool:
return isinstance(v, int) and not isinstance(v, bool) and 0 <= v <= 3 Try / catch
try:
op = RecResizeNorm(**op_cfg)
except Exception as e:
if 'Unsupported interpolation' in str(e):
raise ValueError(f"Use interpolation 0-3 (NEAREST/LINEAR/CUBIC/AREA), got {op_cfg.get('interpolation')}") from e
raise Prevention
- Use raw ints 0-3 in ymls, never cv2 flag objects or strings
- Document the mapping (0 NEAREST, 1 LINEAR, 2 CUBIC, 3 AREA) next to your config
- Validate all preprocess op params in one lint function at startup
When it happens
Trigger: Setting interpolation: 4 (or any int outside 0-3), a string like 'linear', or a cv2 enum constant (cv2.INTER_LANCZOS4 = 4) in the rec preprocessing config for this op.
Common situations: Using Lanczos4 (4) or other OpenCV flags unsupported by this mapper; passing a cv2 constant object instead of its int value; configs ported from torch/torchvision where strings like 'bilinear' are the convention.
Related errors
- RecResizeImg.image_shape is required in rec inference.yml
- Unexpected recognition channels: ${String(channels)}
- Type of target_size is invalid. Now is {}
- not support limit type, image
- {} is not supported in MultiLoss yet
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/e59a4e917ef30e08.
Report an issue: GitHub.