open-mmlab/mmdetection · warning
Got "imgs_per_gpu"={cfg.data.imgs_per_gpu} and "samples_per_
Error message
Got "imgs_per_gpu"={cfg.data.imgs_per_gpu} and "samples_per_gpu"={cfg.data.samples_per_gpu}, "imgs_per_gpu"={cfg.data.imgs_per_gpu} is used in this experiments What it means
The conflict branch of compat_imgs_per_gpu: cfg.data contains both imgs_per_gpu and samples_per_gpu with (potentially) different values. The code warns and then silently prefers the legacy key — cfg.data.samples_per_gpu = cfg.data.imgs_per_gpu overwrites the modern value. So the effective batch size will be imgs_per_gpu regardless of what samples_per_gpu says.
Source
Thrown at mmdet/utils/compat_config.py:43
'type': 'EpochBasedRunner',
'max_epochs': cfg.total_epochs
})
warnings.warn(
'config is now expected to have a `runner` section, '
'please set `runner` in your config.', UserWarning)
else:
if 'total_epochs' in cfg:
assert cfg.total_epochs == cfg.runner.max_epochs
return cfg
def compat_imgs_per_gpu(cfg):
cfg = copy.deepcopy(cfg)
if 'imgs_per_gpu' in cfg.data:
warnings.warn('"imgs_per_gpu" is deprecated in MMDet V2.0. '
'Please use "samples_per_gpu" instead')
if 'samples_per_gpu' in cfg.data:
warnings.warn(
f'Got "imgs_per_gpu"={cfg.data.imgs_per_gpu} and '
f'"samples_per_gpu"={cfg.data.samples_per_gpu}, "imgs_per_gpu"'
f'={cfg.data.imgs_per_gpu} is used in this experiments')
else:
warnings.warn('Automatically set "samples_per_gpu"="imgs_per_gpu"='
f'{cfg.data.imgs_per_gpu} in this experiments')
cfg.data.samples_per_gpu = cfg.data.imgs_per_gpu
return cfg
def compat_loader_args(cfg):
"""Deprecated sample_per_gpu in cfg.data."""
cfg = copy.deepcopy(cfg)
if 'train_dataloader' not in cfg.data:
cfg.data['train_dataloader'] = ConfigDict()
if 'val_dataloader' not in cfg.data:
cfg.data['val_dataloader'] = ConfigDict()View on GitHub (pinned to cfd5d3a985)
Solutions
- Delete imgs_per_gpu from the config so samples_per_gpu is authoritative.
- If you intended samples_per_gpu to win, set the config to only samples_per_gpu=<desired batch size> and re-verify via print(cfg.data.samples_per_gpu) after compat_cfg.
- Search all inherited config files (grep -r imgs_per_gpu configs/) because mmcv config inheritance may inject the legacy key from a base file.
- After fixing, run training with a tiny dry-run to confirm the dataloader batch size matches expectations.
Example fix
# before data = dict(imgs_per_gpu=2, samples_per_gpu=8, ...) # after data = dict(samples_per_gpu=8, ...)
Defensive patterns
Strategy: validation
Validate before calling
from mmcv import Config
def resolve_batch_keys(cfg: Config) -> Config:
data = cfg.data
if 'imgs_per_gpu' in data:
if 'samples_per_gpu' in data and data.imgs_per_gpu != data.samples_per_gpu:
raise ValueError(
f'Conflicting batch sizes: imgs_per_gpu={data.imgs_per_gpu} '
f'vs samples_per_gpu={data.samples_per_gpu}')
data.pop('imgs_per_gpu')
return cfg Prevention
- Keep exactly one batch-size key per config; delete imgs_per_gpu after migration.
- Add a pre-flight assertion that imgs_per_gpu not in cfg.data.
- Remember the shim prefers imgs_per_gpu — verify effective batch size with print(cfg.data.samples_per_gpu) after compat_cfg.
When it happens
Trigger: A config that defines data = dict(imgs_per_gpu=A, samples_per_gpu=B). After the warning, samples_per_gpu is set to A. This is a classic silent-behavior-mismatch trap: the value the developer thinks is active (samples_per_gpu) is not the one used.
Common situations: Half-finished V1→V2 config migrations where samples_per_gpu was added but imgs_per_gpu was never deleted; merging base configs with _delete_ semantics where one parent still carries the old key.
Related errors
- "imgs_per_gpu" is deprecated in MMDet V2.0. Please use "samp
- Automatically set "samples_per_gpu"="imgs_per_gpu"={cfg.data
- The `file_client_args` is deprecated, please use `backend_ar
- The `file_client_args` is deprecated, please use `backend_ar
- config is now expected to have a `runner` section, please se
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/51d0d35a4a17ac70.
Report an issue: GitHub.