{"record":{"id":"9faea00f838e53d5","repo":"docling-project/docling","slug":"supported-input-formats-are-pil-image-image-or-num","errorCode":null,"errorMessage":"Supported input formats are PIL.Image.Image or numpy.ndarray.","messagePattern":"Supported input formats are PIL\\.Image\\.Image or numpy\\.ndarray\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"docling/models/stages/picture_classifier/document_picture_classifier.py","lineNumber":164,"sourceCode":"                yield element.item\n            return\n\n        if self.engine is None:\n            raise RuntimeError(\"Picture classifier engine is not initialized.\")\n\n        images: List[Union[Image.Image, np.ndarray]] = []\n        elements: List[PictureItem] = []\n        for i, el in enumerate(element_batch):\n            assert isinstance(el.item, PictureItem)\n            elements.append(el.item)\n\n            raw_image = el.image\n            if isinstance(raw_image, Image.Image):\n                raw_image = raw_image.convert(\"RGB\")\n            elif isinstance(raw_image, np.ndarray):\n                raw_image = Image.fromarray(raw_image).convert(\"RGB\")\n            else:\n                raise TypeError(\n                    \"Supported input formats are PIL.Image.Image or numpy.ndarray.\"\n                )\n            images.append(raw_image)\n\n        engine_input_batch = [\n            ImageClassificationEngineInput(image=image) for image in images\n        ]\n        engine_output_batch = self.engine.predict_batch(engine_input_batch)\n\n        for item, output in zip(elements, engine_output_batch):\n            predicted_classes = [\n                PictureClassificationClass(\n                    class_name=self._classes[label_id],\n                    confidence=score,\n                )\n                for label_id, score in zip(output.label_ids, output.scores)\n            ]\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/stages/picture_classifier/document_picture_classifier.py#L146-L182","documentation":"Inside the picture-classifier batch loop, each element's image must be either a PIL Image or a numpy ndarray; anything else (None, a path string, bytes, a torch tensor) raises this TypeError after PIL/ndarray conversion is attempted.","triggerScenarios":"Feeding a batch where el.image is not PIL.Image.Image/np.ndarray — e.g. an element built manually with a file path or bytes as image, or a custom pipeline stage that yields wrapper items with the wrong image attribute type.","commonSituations":"Custom NodeItem/PictureItem construction in tests or bespoke pipelines; upgrading pipelines that previously passed paths; elements whose image extraction failed upstream leaving None.","solutions":["Ensure each element's image attribute is a PIL.Image.Image or numpy.ndarray before feeding the stage (load paths with PIL.open / np.asarray).","Check upstream stages that populate el.image; verify none yield None for failed extractions.","If writing custom pipeline glue, convert explicitly: Image.open(path).convert('RGB')."],"exampleFix":"# before\nitem.image = \"figures/fig1.png\"  # path string\n\n# after\nfrom PIL import Image\nitem.image = Image.open(\"figures/fig1.png\").convert(\"RGB\")","handlingStrategy":"type-guard","validationCode":"from PIL import Image\nimport numpy as np\n\ndef valid_batch(batch) -> bool:\n    return all(\n        isinstance(el.image, (Image.Image, np.ndarray)) for el in batch\n    )","typeGuard":"from PIL import Image\nimport numpy as np\nfrom typing import Union\n\ndef is_classifiable_image(img: object) -> bool:\n    return isinstance(img, (Image.Image, np.ndarray))","tryCatchPattern":"try:\n    classifier(items)\nexcept TypeError as e:\n    if \"Supported input formats\" in str(e):\n        items = [normalize(el) for el in items]  # load paths/None -> PIL.Image\n    else:\n        raise","preventionTips":["Normalize images to PIL RGB at ingestion boundaries of custom pipelines.","Reject or repair None images from upstream extraction stages before batching.","Add type assertions in tests for custom NodeItem factories."],"tags":["classification","pictures","type-error","validation"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}