{"record":{"id":"2fb345686eb8e312","repo":"opendatalab/MinerU","slug":"the-img-type-type-img-does-not-in-inputtype","errorCode":null,"errorMessage":"The img type {type(img)} does not in {InputType.__args__}","messagePattern":"The img type (.+?) does not in (.+?)","errorType":"exception","errorClass":"LoadImageError","httpStatus":null,"severity":"error","filePath":"mineru/model/table/rec/unet_table/utils.py","lineNumber":87,"sourceCode":"            raise ONNXRuntimeError(error_info) from e\n\n    def get_input_names(self) -> List[str]:\n        return [v.name for v in self.session.get_inputs()]\n\n\nclass ONNXRuntimeError(Exception):\n    pass\n\n\nclass LoadImage:\n    def __init__(\n        self,\n    ):\n        pass\n\n    def __call__(self, img: InputType) -> np.ndarray:\n        if not isinstance(img, InputType.__args__):\n            raise LoadImageError(\n                f\"The img type {type(img)} does not in {InputType.__args__}\"\n            )\n\n        img = self.load_img(img)\n        img = self.convert_img(img)\n        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)))","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/table/rec/unet_table/utils.py#L69-L105","documentation":"LoadImage.__call__ validates the input against the InputType union (str, Path, bytes, np.ndarray, PIL Image). Passing any other type — torch tensor, dict, list, None — raises LoadImageError listing the received type and the accepted set.","triggerScenarios":"Calling the loader with a torch.Tensor, a list of images, or None (e.g. a failed upstream crop returned None).","commonSituations":"Bridging PyTorch-based layout detection outputs into this OpenCV-based table pipeline, or optional fields that silently become None.","solutions":["Convert tensors: arr = t.detach().cpu().numpy().astype(np.uint8).","None-check optional inputs before calling the loader.","For lists, loop and load each item individually."],"exampleFix":"# before\nimg = load_image(tensor_crop)\n\n# after\nimg = load_image(tensor_crop.detach().cpu().numpy())","handlingStrategy":"type-guard","validationCode":"from PIL import Image\nimport numpy as np\nACCEPTED = (str, Path, bytes, np.ndarray, Image.Image)\nif not isinstance(img, ACCEPTED):\n    img = np.asarray(img) if hasattr(img, '__array__') else None","typeGuard":"def is_loader_input(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":["Convert torch tensors via .detach().cpu().numpy() before this loader.","None-check optional crops upstream.","Keep one shared to_ndarray helper for the whole pipeline."],"tags":["image-processing","type-validation","table-recognition"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}