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_system hubserving module's predict method when the request violates its input contract. Exactly one of `images` (list of numpy HxWxC arrays) or `paths` (list of path strings) must be a non-empty list; all other inputs reach the else branch and raise TypeError.

Source

Thrown at deploy/hubserving/ocr_system/module.py:115

            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()
            dt_boxes, rec_res, _ = self.text_sys(img)
            elapse = time.time() - starttime
            logger.info("Predict time: {}".format(elapse))

            dt_num = len(dt_boxes)
            rec_res_final = []

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Send one and only one non-empty array field: {"images": [...]} or {"paths": [...]}.
  2. Expand directories to explicit file lists client-side before sending.
  3. In-process: call predict(images=[...], paths=[]) or predict(images=[], paths=[...]).

Example fix

# before
payload = {"images": [], "paths": []}  # both empty -> TypeError

# after
payload = {"paths": ["docs/page1.png", "docs/page2.png"]}
Defensive patterns

Strategy: validation

Validate before calling

def valid_system_payload(data: dict) -> bool:
    imgs, paths = data.get("images", []), data.get("paths", [])
    return (bool(imgs) and isinstance(imgs, list) and not paths) or (
        bool(paths) and isinstance(paths, list) and not imgs
    )

Type guard

def exactly_one_list(a, b) -> bool:
    a_ok = isinstance(a, list) and len(a) > 0
    b_ok = isinstance(b, list) and len(b) > 0
    return a_ok != b_ok

Try / catch

try:
    res = mod.predict(images=images, paths=paths)
except TypeError as e:
    if "inconsistent" in str(e):
        raise ValueError("images XOR paths required, got both/neither") from e
    raise

Prevention

When it happens

Trigger: predict invoked with images and paths both non-empty, both empty, or either not being a list.

Common situations: Posting a request with both keys filled because the client supports both modes; passing a directory path string instead of a list of file paths; empty batch from an upstream image feeder.

Related errors


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