{"record":{"id":"2e680cab52ef706f","repo":"open-mmlab/mmdetection","slug":"imgs-per-gpu-is-deprecated-in-mmdet-v2-0-please","errorCode":null,"errorMessage":"\"imgs_per_gpu\" is deprecated in MMDet V2.0. Please use \"samples_per_gpu\" instead","messagePattern":"\"imgs_per_gpu\" is deprecated in MMDet V2\\.0\\. Please use \"samples_per_gpu\" instead","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/utils/compat_config.py","lineNumber":40,"sourceCode":"def compat_runner_args(cfg):\n    if 'runner' not in cfg:\n        cfg.runner = ConfigDict({\n            'type': 'EpochBasedRunner',\n            'max_epochs': cfg.total_epochs\n        })\n        warnings.warn(\n            'config is now expected to have a `runner` section, '\n            'please set `runner` in your config.', UserWarning)\n    else:\n        if 'total_epochs' in cfg:\n            assert cfg.total_epochs == cfg.runner.max_epochs\n    return cfg\n\n\ndef compat_imgs_per_gpu(cfg):\n    cfg = copy.deepcopy(cfg)\n    if 'imgs_per_gpu' in cfg.data:\n        warnings.warn('\"imgs_per_gpu\" is deprecated in MMDet V2.0. '\n                      'Please use \"samples_per_gpu\" instead')\n        if 'samples_per_gpu' in cfg.data:\n            warnings.warn(\n                f'Got \"imgs_per_gpu\"={cfg.data.imgs_per_gpu} and '\n                f'\"samples_per_gpu\"={cfg.data.samples_per_gpu}, \"imgs_per_gpu\"'\n                f'={cfg.data.imgs_per_gpu} is used in this experiments')\n        else:\n            warnings.warn('Automatically set \"samples_per_gpu\"=\"imgs_per_gpu\"='\n                          f'{cfg.data.imgs_per_gpu} in this experiments')\n        cfg.data.samples_per_gpu = cfg.data.imgs_per_gpu\n    return cfg\n\n\ndef compat_loader_args(cfg):\n    \"\"\"Deprecated sample_per_gpu in cfg.data.\"\"\"\n\n    cfg = copy.deepcopy(cfg)\n    if 'train_dataloader' not in cfg.data:","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/utils/compat_config.py#L22-L58","documentation":"compat_imgs_per_gpu warns that imgs_per_gpu, the MMDet V1.x batch-size key under cfg.data, is deprecated in V2.0 in favor of samples_per_gpu. It fires whenever 'imgs_per_gpu' is present in cfg.data, before it copies the value over (and possibly warns about a conflict, see error 325).","triggerScenarios":"Any tools/train.py / tools/test.py invocation (both call compat_cfg → compat_imgs_per_gpu) with a config containing data = dict(..., imgs_per_gpu=N). The warning is emitted unconditionally once the key exists.","commonSituations":"Using legacy or third-party configs written for MMDet 1.x with a 2.x install; upgrading a project across the V1→V2 boundary; copying old detection challenge baseline configs.","solutions":["Rename the key in your config: data = dict(..., samples_per_gpu=N) and delete imgs_per_gpu.","If both keys exist, remove imgs_per_gpu to avoid the follow-up conflict warning (error 325).","Note samples_per_gpu can also be split per split (train_dataloader=dict(samples_per_gpu=...) in later versions) — follow your installed version's config style.","Run mmcv.Config.fromfile(...).data on the sanitized config to confirm only samples_per_gpu remains."],"exampleFix":"# before\ndata = dict(imgs_per_gpu=4, workers_per_gpu=2, ...)\n# after\ndata = dict(samples_per_gpu=4, workers_per_gpu=2, ...)","handlingStrategy":"validation","validationCode":"from mmcv import Config\n\ndef modernize_batch_key(cfg: Config) -> Config:\n    if 'imgs_per_gpu' in cfg.data:\n        cfg.data.samples_per_gpu = cfg.data.pop('imgs_per_gpu')\n    return cfg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write samples_per_gpu (not imgs_per_gpu) in all new mmdet 2.x configs.","grep -r imgs_per_gpu configs/ during migrations to catch stragglers.","Validate configs load cleanly via Config.fromfile before launching long training jobs."],"tags":["mmdetection","config","deprecation","batch-size","migration"],"backgroundTag":"deprecated-config-key","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}