{"record":{"id":"b05dfbc0b113e8c9","repo":"opendatalab/MinerU","slug":"type-img-is-not-supported","errorCode":null,"errorMessage":"{type(img)} is not supported!","messagePattern":"(.+?) is not supported!","errorType":"exception","errorClass":"LoadImageError","httpStatus":null,"severity":"error","filePath":"mineru/model/table/rec/unet_table/utils.py","lineNumber":111,"sourceCode":"        return img\n\n    def load_img(self, img: InputType) -> np.ndarray:\n        if isinstance(img, (str, Path)):\n            self.verify_exist(img)\n            try:\n                img = np.array(Image.open(img))\n            except UnidentifiedImageError as e:\n                raise LoadImageError(f\"cannot identify image file {img}\") from e\n            return img\n\n        if isinstance(img, bytes):\n            img = np.array(Image.open(BytesIO(img)))\n            return img\n\n        if isinstance(img, np.ndarray):\n            return img\n\n        raise LoadImageError(f\"{type(img)} is not supported!\")\n\n    def convert_img(self, img: np.ndarray):\n        if img.ndim == 2:\n            return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)\n\n        if img.ndim == 3:\n            channel = img.shape[2]\n            if channel == 1:\n                return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)\n\n            if channel == 2:\n                return self.cvt_two_to_three(img)\n\n            if channel == 4:\n                return self.cvt_four_to_three(img)\n\n            if channel == 3:\n                return cv2.cvtColor(img, cv2.COLOR_RGB2BGR)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/table/rec/unet_table/utils.py#L93-L129","documentation":"load_img's terminal branch: the value is not str/Path, bytes, or ndarray, so it is not supported. In normal flow __call__ already rejects such types, so this fires mainly when load_img is called directly or when InputType was widened inconsistently.","triggerScenarios":"Subclass or caller invoking load_img() directly with a PIL Image (not handled in load_img!), torch tensor, or other object, bypassing __call__.","commonSituations":"Refactors that call the internal method instead of __call__, or passing PIL Images assuming the str/bytes branches cover them.","solutions":["Call the loader instance (__call__) instead of load_img: img = load_image(pil_or_path).","Convert before calling load_img directly: np.asarray(pil_img) for PIL, .cpu().numpy() for tensors."],"exampleFix":"# before\nimg = loader.load_img(pil_image)  # PIL not handled in load_img\n\n# after\nimg = loader(pil_image)  # go through __call__","handlingStrategy":"type-guard","validationCode":"assert hasattr(loader, '__call__')\nimg = loader(img)  # never call loader.load_img directly","typeGuard":"def goes_through_call(img) -> bool:\n    from PIL import Image\n    import numpy as np\n    return isinstance(img, (str, Path, bytes, np.ndarray, Image.Image))","tryCatchPattern":null,"preventionTips":["Treat load_img/convert_img as private internals; use the instance call.","In code review, flag direct .load_img( calls outside the class."],"tags":["image-processing","api-misuse","table-recognition"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}