open-mmlab/mmdetection · error · ValueError
LoadImageFromFile is not found in the test pipeline
Error message
LoadImageFromFile is not found in the test pipeline
What it means
DetInferencer requires the test pipeline config to contain a LoadImageFromFile transform, which it replaces with InferencerLoader to handle arbitrary input sources (paths, arrays, dirs, URLs). If no transform named 'LoadImageFromFile' (or the imported class type) exists in the pipeline list, _get_transform_idx returns -1 and this ValueError is raised from _init_pipeline. It almost always means the config's test_pipeline omits or renames the image loading step.
Source
Thrown at mmdet/apis/det_inferencer.py:172
warnings.warn(
'palette does not exist, random is used by default. '
'You can also set the palette to customize.')
model.dataset_meta['palette'] = 'random'
def _init_pipeline(self, cfg: ConfigType) -> Compose:
"""Initialize the test pipeline."""
pipeline_cfg = cfg.test_dataloader.dataset.pipeline
# For inference, the key of ``img_id`` is not used.
if 'meta_keys' in pipeline_cfg[-1]:
pipeline_cfg[-1]['meta_keys'] = tuple(
meta_key for meta_key in pipeline_cfg[-1]['meta_keys']
if meta_key != 'img_id')
load_img_idx = self._get_transform_idx(
pipeline_cfg, ('LoadImageFromFile', LoadImageFromFile))
if load_img_idx == -1:
raise ValueError(
'LoadImageFromFile is not found in the test pipeline')
pipeline_cfg[load_img_idx]['type'] = 'mmdet.InferencerLoader'
return Compose(pipeline_cfg)
def _get_transform_idx(self, pipeline_cfg: ConfigType,
name: Union[str, Tuple[str, type]]) -> int:
"""Returns the index of the transform in a pipeline.
If the transform is not found, returns -1.
"""
for i, transform in enumerate(pipeline_cfg):
if transform['type'] in name:
return i
return -1
def _init_visualizer(self, cfg: ConfigType) -> Optional[Visualizer]:
"""Initialize visualizers.
View on GitHub (pinned to cfd5d3a985)
Solutions
- Add {'type': 'LoadImageFromFile'} as the first step of the test pipeline in the config (test_dataloader.dataset.pipeline or test_pipeline)
- Verify the pipeline you passed actually is the *test* pipeline, not train_pipeline
- If building the config dict programmatically, prepend the transform: pipeline.insert(0, dict(type='LoadImageFromFile'))
- Check for typos such as 'LoadImageFromFile ' or a wrong scope prefix in the type string
Example fix
// before
test_pipeline = [
dict(type='LoadAnnotations', with_bbox=True),
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
dict(type='PackDetInputs'),
]
// after
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
dict(type='PackDetInputs', meta_keys=('img_id','img_path','ori_shape','img_shape','scale_factor')),
] Defensive patterns
Strategy: validation
Validate before calling
from mmengine.config import Config
cfg = Config.fromfile(config_path)
pipeline = cfg.test_dataloader.dataset.pipeline # or cfg.test_pipeline
names = [t['type'] for t in pipeline if isinstance(t, dict)]
assert 'LoadImageFromFile' in names, f'test pipeline missing LoadImageFromFile: {names}' Type guard
def has_image_loader(cfg) -> bool:
pipe = (cfg.get('test_dataloader', {}).get('dataset', {}).get('pipeline')
or cfg.get('test_pipeline') or [])
return any(isinstance(t, dict) and t.get('type') == 'LoadImageFromFile' for t in pipe) Try / catch
try:
inferencer = DetInferencer(cfg, weights=ckpt)
except ValueError as e:
if 'LoadImageFromFile' in str(e):
raise SystemExit(f'Fix test pipeline in {config_path}: prepend LoadImageFromFile')
raise Prevention
- Start from an official config under configs/ rather than writing pipelines from scratch
- Add a startup assertion that the test pipeline's first transform is LoadImageFromFile
- Keep pipeline entries as dicts with a 'type' key matching registered transform names exactly
When it happens
Trigger: Constructing DetInferencer(model=..., config=...) where the config's test_dataloader.dataset.pipeline lacks an entry with type='LoadImageFromFile' (e.g., custom pipeline that loads arrays, or a pipeline that uses a different loader type). Also happens when passing a train-only config or a hand-written config dict whose pipeline starts at LoadAnnotations.
Common situations: Custom configs with modified test pipelines, configs for models that expect pre-loaded numpy arrays, typos in the transform type string, or reusing an MMClassification/other-repo config with mmdet's DetInferencer.
Related errors
- Visualization needs the "visualizer" termdefined in the conf
- 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/45b991865ccb1122.
Report an issue: GitHub.