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_det hubserving module's predict method when input validation fails. The API contract is: exactly one of `images` (list of HxWxC numpy arrays) or `paths` (list of path strings), non-empty and of list type. Everything else hits the else branch and raises TypeError.

Source

Thrown at deploy/hubserving/ocr_det/module.py:114

            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."

        all_results = []
        for img in predicted_data:
            if img is None:
                logger.info("error in loading image")
                all_results.append([])
                continue
            dt_boxes, elapse = self.text_detector(img)
            logger.info("Predict time : {}".format(elapse))

            rec_res_final = []
            for dno in range(len(dt_boxes)):
                rec_res_final.append(
                    {"text_region": dt_boxes[dno].astype(np.int32).tolist()}

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Populate exactly one field with a non-empty list and drop the other from the payload entirely.
  2. Check the request JSON before sending: exactly one of images/paths present, and it is an array with length >= 1.
  3. In-process callers: pass lists explicitly, e.g. predict(images=[np.ndarray], paths=[]).

Example fix

# before
payload = {"images": imgs, "paths": ["extra.jpg"]}  # both -> TypeError

# after
payload = {"images": imgs}
# or
payload = {"paths": ["extra.jpg"]}
Defensive patterns

Strategy: validation

Validate before calling

def valid_det_payload(data: dict) -> bool:
    has_img = isinstance(data.get("images"), list) and data["images"]
    has_path = isinstance(data.get("paths"), list) and data["paths"]
    return has_img != has_path  # exactly one true

Type guard

from typing import Any

def xor_payload(images: Any, paths: Any) -> bool:
    ok_img = isinstance(images, list) and len(images) > 0
    ok_path = isinstance(paths, list) and len(paths) > 0
    return ok_img ^ ok_path

Try / catch

try:
    res = mod.predict(images=images, paths=paths)
except TypeError as e:
    if "inconsistent" in str(e):
        raise ValueError("send exactly one of images[] or paths[]") from e
    raise

Prevention

When it happens

Trigger: predict called with both images and paths populated, both empty, a non-list value for either argument, or images supplied via paths (or vice versa).

Common situations: Client sends {"images": [], "paths": []}; a request payload built by copying a template that includes both keys; passing a tuple or generator instead of a list when calling the module in-process.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/7aa3f78bcfac1544. Report an issue: GitHub.