PaddlePaddle/PaddleOCR · error · TypeError
The input data is inconsistent with expectations.
Error message
The input data is inconsistent with expectations.
What it means
Raised as TypeError by the kie_ser hub module's predict() when the arguments match neither accepted shape: a non-empty images list with paths == [], or images == [] with a non-empty paths list. Passing both, neither, non-list values, or None (None != [] is True but isinstance(None, list) is False) all fail the exclusive-or style check. It is an input-contract error on the hub HTTP predict handler.
Source
Thrown at deploy/hubserving/kie_ser/module.py:115
continue
images.append(img)
return images
def predict(self, images=[], paths=[]):
"""
Get the chinese texts 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 chinese texts 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."
all_results = []
for img in predicted_data:
if img is None:
logger.info("error in loading image")
all_results.append([])
continue
starttime = time.time()
ser_res, _, elapse = self.ser_predictor(img)
elapse = time.time() - starttime
logger.info("Predict time: {}".format(elapse))
all_results.append(ser_res)
return all_results
View on GitHub (pinned to 2661c7c0ef)
Solutions
- Send exactly one input form: {"images": [ndarray, ...], "paths": []} or {"images": [], "paths": ["/data/a.jpg", ...]}
- Ensure both fields are JSON arrays (never null) in the request body
- Decode base64 images to numpy arrays (cv2.imdecode) before calling the python API
- Verify at least one element is present in the chosen list
Example fix
# before res = module.predict(images=None, paths=None) # TypeError # after res = module.predict(images=[], paths=["/data/invoice_01.jpg"]) # or res = module.predict(images=[img_ndarray], paths=[])
Defensive patterns
Strategy: validation
Validate before calling
def valid_predict_input(images, paths) -> bool:
images_ok = isinstance(images, list) and len(images) > 0
paths_ok = isinstance(paths, list) and len(paths) > 0
return (images_ok and paths == []) or (paths_ok and images == [])
assert valid_predict_input(images, paths), "pass exactly one of images/paths as non-empty lists" Type guard
from typing import Any
def is_predict_payload(data: Any) -> bool:
images = data.get("images") if isinstance(data, dict) else None
paths = data.get("paths") if isinstance(data, dict) else None
if not (isinstance(images, list) and isinstance(paths, list)):
return False
return bool(images) != bool(paths) # exactly one non-empty Try / catch
try:
results = module.predict(images=images, paths=paths)
except TypeError as e:
if "inconsistent with expectations" in str(e):
# normalize inputs and retry with exactly one form
results = module.predict(images=[], paths=[str(p) for p in paths or []])
else:
raise Prevention
- Always send both keys as JSON arrays, defaulting the unused one to []
- Decode base64 to ndarrays before calling the python API
- Wrap hub HTTP handlers with a payload schema check
When it happens
Trigger: POSTing {"images": null, "paths": null} or {"images": [...], "paths": [...]} to the hub endpoint; sending a single numpy array instead of a list; passing a string path in images; empty lists on both sides; a dict payload the handler forwards verbatim.
Common situations: Client code copying the OCR (det+rec) hub client but omitting the paths field default; JSON clients sending null instead of []; sending base64 strings where the module expects decoded ndarrays.
Related errors
- Environment Variable CUDA_VISIBLE_DEVICES is not set correct
- Environment Variable CUDA_VISIBLE_DEVICES is not set correct
- Unsupported model: {model!r}
- Unknown provider: {provider}
- Unsupported model: {normalized!r}. Supported models: {suppor
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/76971d3f83a87f76.
Report an issue: GitHub.