PaddlePaddle/PaddleOCR · error · TypeError
The input data is inconsistent with expectations.
Error message
The input data is inconsistent with expectations.
What it means
Raised by the ocr_cls hubserving module's predict method when the input does not match the expected shape. The module takes either `images` (list of HxWxC numpy arrays) or `paths` (list of image file path strings) — exactly one non-empty list. Any other combination or type falls through to this TypeError.
Source
Thrown at deploy/hubserving/ocr_cls/module.py:112
images.append(img)
return images
def predict(self, images=[], paths=[]):
"""
Get the text angle in the predicted images.
Args:
images (list(numpy.ndarray)): images data, shape of each is [H, W, C]. If images not paths
paths (list[str]): The paths of images. If paths not images
Returns:
res (list): The result of text detection box and save path of images.
"""
if images != [] and isinstance(images, list) and paths == []:
predicted_data = images
elif images == [] and isinstance(paths, list) and paths != []:
predicted_data = self.read_images(paths)
else:
raise TypeError("The input data is inconsistent with expectations.")
assert (
predicted_data != []
), "There is not any image to be predicted. Please check the input data."
img_list = []
for img in predicted_data:
if img is None:
continue
img_list.append(img)
rec_res_final = []
try:
img_list, cls_res, predict_time = self.text_classifier(img_list)
for dno in range(len(cls_res)):
angle, score = cls_res[dno]
rec_res_final.append(
{View on GitHub (pinned to 2661c7c0ef)
Solutions
- Send exactly one non-empty JSON array: {"images": [...]} or {"paths": ["img1.jpg", "img2.jpg"]}.
- Wrap single items in a list (paths=["single.jpg"], not paths="single.jpg").
- When calling the class in Python, use predict(images=[arr], paths=[]) or predict(images=[], paths=[...]).
Example fix
# before res = mod.predict(images=[], paths="doc.png") # string, not list -> TypeError # after res = mod.predict(images=[], paths=["doc.png"])
Defensive patterns
Strategy: validation
Validate before calling
def valid_cls_payload(data: dict) -> bool:
images, paths = data.get("images", []), data.get("paths", [])
one = lambda v: isinstance(v, list) and len(v) > 0
return (one(images) and not one(paths)) or (one(paths) and not one(images)) Type guard
def is_images_arg(v) -> bool:
return isinstance(v, list) and len(v) > 0 and all(im is not None for im in v)
def is_paths_arg(v) -> bool:
return isinstance(v, list) and len(v) > 0 and all(isinstance(p, str) for p in v) Try / catch
try:
res = mod.predict(images=images, paths=paths)
except TypeError as e:
if "inconsistent" in str(e):
return {"error": "invalid payload", "detail": str(e)}, 400
raise Prevention
- Always wrap single inputs in a list before calling predict.
- Never include both images and paths keys in one request.
- Validate payloads in the HTTP handler before they reach the module.
When it happens
Trigger: Calling predict with both `images` and `paths` non-empty, both empty, `paths` as a bare string instead of a list, or `images` as a single ndarray instead of a list of arrays.
Common situations: POSTing {"paths": "single.jpg"} (string, not array) to the served endpoint; sending both keys in one request; adapting a script from PaddleOCR's command-line tools where a single image object is passed directly.
Related errors
- The input data is inconsistent with expectations.
- The input data is inconsistent with expectations.
- The input data is inconsistent with expectations.
- The input data is inconsistent with expectations.
- The input data is inconsistent with expectations.
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/44e4c2c75699dae1.
Report an issue: GitHub.