open-mmlab/mmdetection · error · ValueError
Unsupported input type: {type(single_input)}
Error message
Unsupported input type: {type(single_input)} What it means
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.
Source
Thrown at mmdet/apis/det_inferencer.py:485
if self.visualizer is None:
raise ValueError('Visualization needs the "visualizer" term'
'defined in the config, but got None.')
results = []
for single_input, pred in zip(inputs, preds):
if isinstance(single_input, str):
img_bytes = mmengine.fileio.get(single_input)
img = mmcv.imfrombytes(img_bytes)
img = img[:, :, ::-1]
img_name = osp.basename(single_input)
elif isinstance(single_input, np.ndarray):
img = single_input.copy()
img_num = str(self.num_visualized_imgs).zfill(8)
img_name = f'{img_num}.jpg'
else:
raise ValueError('Unsupported input type: '
f'{type(single_input)}')
out_file = osp.join(img_out_dir, 'vis',
img_name) if img_out_dir != '' else None
self.visualizer.add_datasample(
img_name,
img,
pred,
show=show,
wait_time=wait_time,
draw_gt=False,
draw_pred=draw_pred,
pred_score_thr=pred_score_thr,
out_file=out_file,
)
results.append(self.visualizer.get_image())
self.num_visualized_imgs += 1View on GitHub (pinned to cfd5d3a985)
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
Example fix
// before
from PIL import Image
img = Image.open('a.jpg')
inferencer(img, show=True) # ValueError
// after
import numpy as np
img = np.asarray(Image.open('a.jpg').convert('RGB'))
inferencer(img, show=True) Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np inputs = [np.asarray(x) if hasattr(x, 'convert') or hasattr(x, 'mode') else x for x in inputs] # PIL -> np assert all(isinstance(i, (str, np.ndarray)) for i in inputs), 'inputs must be str paths or np.ndarray'
Type guard
import numpy as np
def is_inferencer_input_ok(x) -> bool:
return isinstance(x, (str, np.ndarray)) Try / catch
try:
inferencer(inputs, show=True)
except ValueError as e:
if 'Unsupported input type' in str(e):
raise TypeError('Convert PIL/tensor inputs to np.ndarray or pass file paths')
raise Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- LoadImageFromFile is not found in the test pipeline
- Visualization needs the "visualizer" termdefined in the conf
- palette does not match classes as metainfo is {self._metainf
- trackeval is not installed,please install it by: pip install
- palette does not exist, random is used by default. You can a
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/960c638af6e05298.
Report an issue: GitHub.