{"record":{"id":"960c638af6e05298","repo":"open-mmlab/mmdetection","slug":"unsupported-input-type-type-single-input","errorCode":null,"errorMessage":"Unsupported input type: {type(single_input)}","messagePattern":"Unsupported input type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/apis/det_inferencer.py","lineNumber":485,"sourceCode":"\n        if self.visualizer is None:\n            raise ValueError('Visualization needs the \"visualizer\" term'\n                             'defined in the config, but got None.')\n\n        results = []\n\n        for single_input, pred in zip(inputs, preds):\n            if isinstance(single_input, str):\n                img_bytes = mmengine.fileio.get(single_input)\n                img = mmcv.imfrombytes(img_bytes)\n                img = img[:, :, ::-1]\n                img_name = osp.basename(single_input)\n            elif isinstance(single_input, np.ndarray):\n                img = single_input.copy()\n                img_num = str(self.num_visualized_imgs).zfill(8)\n                img_name = f'{img_num}.jpg'\n            else:\n                raise ValueError('Unsupported input type: '\n                                 f'{type(single_input)}')\n\n            out_file = osp.join(img_out_dir, 'vis',\n                                img_name) if img_out_dir != '' else None\n\n            self.visualizer.add_datasample(\n                img_name,\n                img,\n                pred,\n                show=show,\n                wait_time=wait_time,\n                draw_gt=False,\n                draw_pred=draw_pred,\n                pred_score_thr=pred_score_thr,\n                out_file=out_file,\n            )\n            results.append(self.visualizer.get_image())\n            self.num_visualized_imgs += 1","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/apis/det_inferencer.py#L467-L503","documentation":"In DetInferencer.visualize, each input must be either a str path (or directory) or a numpy ndarray image. Any other type (e.g., a PIL Image, torch tensor, list, or bytes) falls into the else branch and raises 'Unsupported input type'. The type check happens per-element of the inputs list after inference, during the visualization loop.","triggerScenarios":"Calling the inferencer with show/return_vis/img_out_dir enabled and inputs containing PIL.Image objects, torch tensors, raw file bytes, or nested lists instead of plain str paths or np.ndarray images.","commonSituations":"Wrapping the inferencer in a service that decodes images with PIL first, passing cv2.imread results mixed with PIL objects, or passing a numpy array of dtype object. Note visualize is only reached when visualization is requested; without it, __call__ preprocess may handle some types differently.","solutions":["Convert PIL images to numpy before calling: img = np.asarray(pil_img)[:, :, ::-1] (BGR) or pass RGB consistently with the pipeline's image loading convention","Pass file paths (str) or directory paths instead of decoded objects","Ensure every element of the inputs list is uniformly str or np.ndarray, not a mix"],"exampleFix":"// before\nfrom PIL import Image\nimg = Image.open('a.jpg')\ninferencer(img, show=True)  # ValueError\n// after\nimport numpy as np\nimg = np.asarray(Image.open('a.jpg').convert('RGB'))\ninferencer(img, show=True)","handlingStrategy":"type-guard","validationCode":"import numpy as np\ninputs = [np.asarray(x) if hasattr(x, 'convert') or hasattr(x, 'mode') else x for x in inputs]  # PIL -> np\nassert all(isinstance(i, (str, np.ndarray)) for i in inputs), 'inputs must be str paths or np.ndarray'","typeGuard":"import numpy as np\ndef is_inferencer_input_ok(x) -> bool:\n    return isinstance(x, (str, np.ndarray))","tryCatchPattern":"try:\n    inferencer(inputs, show=True)\nexcept ValueError as e:\n    if 'Unsupported input type' in str(e):\n        raise TypeError('Convert PIL/tensor inputs to np.ndarray or pass file paths') \n    raise","preventionTips":["Standardize on file-path strings at service boundaries","Convert PIL via np.asarray(pil_img) and torch tensors via tensor.mul(255).byte().cpu().numpy().transpose(1,2,0) before calling","Validate the whole inputs list before the call since the error surfaces late (in visualize)"],"tags":["mmdetection","inferencer","visualization","input-type","numpy"],"backgroundTag":"unsupported-argument-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}