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_rec hubserving module's predict method when the images/paths input contract is violated. The method requires exactly one non-empty list: either `images` (list of numpy image arrays) or `paths` (list of image file paths). Any other combination raises TypeError before any inference runs.
Source
Thrown at deploy/hubserving/ocr_rec/module.py:112
images.append(img)
return images
def predict(self, images=[], paths=[]):
"""
Get the text box 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:
rec_res, predict_time = self.text_recognizer(img_list)
for dno in range(len(rec_res)):
text, score = rec_res[dno]
rec_res_final.append(
{View on GitHub (pinned to 2661c7c0ef)
Solutions
- Send exactly one key as a non-empty array: {"images": [...]} xor {"paths": [...]}.
- Wrap scalar inputs in a one-element list.
- Validate the payload client-side before POSTing to the served endpoint.
Example fix
# before res = mod.predict(images=arr, paths=[]) # ndarray, not list -> TypeError # after res = mod.predict(images=[arr], paths=[])
Defensive patterns
Strategy: validation
Validate before calling
def valid_rec_request(images, paths) -> bool:
return (isinstance(images, list) and images and paths == []) or (
isinstance(paths, list) and paths and images == []
) Type guard
def as_list(v):
if isinstance(v, list):
return v
return [v] # wrap scalars/arrays so predict never sees a bare value Try / catch
try:
res = mod.predict(images=images, paths=paths)
except TypeError as e:
if "inconsistent" in str(e):
return [], 400 # bad request, log payload for triage
raise Prevention
- Normalize inputs through an as_list() helper on the client side.
- Assert exactly one input mode in request-building code.
- Unit-test the client payload builder against the module contract.
When it happens
Trigger: Both images and paths supplied; both empty; either argument not a list (e.g. paths as a bare string or images as a single ndarray).
Common situations: Sending a recognition request with {"paths": "img.jpg"} instead of an array; batching scripts that pass images and paths together for logging purposes; empty request bodies from upstream services.
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/1af5d6b1dfe5e8ad.
Report an issue: GitHub.