open-mmlab/mmdetection · error · ValueError
Visualization needs the "visualizer" termdefined in the conf
Error message
Visualization needs the "visualizer" termdefined in the config, but got None.
What it means
DetInferencer.visualize() raises this when visualization is requested (show=True, img_out_dir set, or return_vis=True) but self.visualizer is None. The visualizer is only constructed when the config defines a 'visualizer' term (via default_scope/hooks init or the visualizer key in the config); if the config lacks it or was passed as None, visualization cannot proceed.
Source
Thrown at mmdet/apis/det_inferencer.py:469
pred_score_thr (float): Minimum score of bboxes to draw.
Defaults to 0.3.
no_save_vis (bool): Whether to force not to save prediction
vis results. Defaults to False.
img_out_dir (str): Output directory of visualization results.
If left as empty, no file will be saved. Defaults to ''.
Returns:
List[np.ndarray] or None: Returns visualization results only if
applicable.
"""
if no_save_vis is True:
img_out_dir = ''
if not show and img_out_dir == '' and not return_vis:
return None
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)}')
View on GitHub (pinned to cfd5d3a985)
Solutions
- Add a visualizer block to the config: visualizer=dict(type='DetLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer')
- Only pass show=False / img_out_dir='' / return_vis=False (the default) if you don't need visualization, which returns None before the check
- Ensure the config is a complete mmdet config (copy from an existing config in configs/ rather than writing from scratch)
Example fix
// before
cfg = dict(model=model_cfg, test_pipeline=pipeline) # no visualizer
infer = DetInferencer(cfg, weights='ckpt.pth')
res = infer('img.jpg', show=True)
// after
cfg = dict(model=model_cfg, test_pipeline=pipeline,
visualizer=dict(type='DetLocalVisualizer',
vis_backends=[dict(type='LocalVisBackend')],
name='visualizer'))
infer = DetInferencer(cfg, weights='ckpt.pth')
res = infer('img.jpg', show=True) Defensive patterns
Strategy: validation
Validate before calling
wants_vis = show or img_out_dir or return_vis
if wants_vis:
assert inferencer.visualizer is not None, \
'config has no visualizer term; add one or disable show/return_vis/img_out_dir' Type guard
def can_visualize(inferencer) -> bool:
return inferencer.visualizer is not None Try / catch
try:
vis = inferencer(inputs, return_vis=True).visualization
except ValueError as e:
if 'visualizer' in str(e):
vis = None # degrade gracefully
else:
raise Prevention
- Include a visualizer block in every inferencer config
- Default show=False and return_vis=False in batch/service code and only enable after asserting visualizer exists
- Smoke-test the config once at app startup
When it happens
Trigger: Calling DetInferencer(...) with show=True, return_vis=True, or a non-empty img_out_dir, while the underlying config has no visualizer definition or the inferencer was constructed with a minimal/hand-written config missing the visualizer key.
Common situations: Using custom stripped-down configs, initializing the inferencer from a raw Config object rather than a full model config, or versions where visualizer setup depends on cfg.visualizer being present in the config file.
Related errors
- LoadImageFromFile is not found in the test pipeline
- Unsupported input type: {type(single_input)}
- config must be a filename or Config object, but got {type(co
- Unrecognized dataset: {dataset}
- The `file_client_args` is deprecated, please use `backend_ar
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/bad2104ea5438b5c.
Report an issue: GitHub.