{"record":{"id":"86329ecd0a412f80","repo":"open-mmlab/mmdetection","slug":"automatically-set-samples-per-gpu-imgs-per-gpu","errorCode":null,"errorMessage":"Automatically set \"samples_per_gpu\"=\"imgs_per_gpu\"={cfg.data.imgs_per_gpu} in this experiments","messagePattern":"Automatically set \"samples_per_gpu\"=\"imgs_per_gpu\"=(.+?) in this experiments","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"mmdet/utils/compat_config.py","lineNumber":48,"sourceCode":"            '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:\n        cfg.data['train_dataloader'] = ConfigDict()\n    if 'val_dataloader' not in cfg.data:\n        cfg.data['val_dataloader'] = ConfigDict()\n    if 'test_dataloader' not in cfg.data:\n        cfg.data['test_dataloader'] = ConfigDict()\n\n    # special process for train_dataloader\n    if 'samples_per_gpu' in cfg.data:","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/utils/compat_config.py#L30-L66","documentation":"The non-conflict branch of compat_imgs_per_gpu: imgs_per_gpu exists, samples_per_gpu does not, so the shim sets cfg.data.samples_per_gpu = cfg.data.imgs_per_gpu and informs you of the automatic mapping. Behavior is correct — this is a migration notice so you update the config to V2 naming.","triggerScenarios":"tools/train.py or tools/test.py with a config containing only data = dict(..., imgs_per_gpu=N). After this warning the config behaves as if samples_per_gpu=N were set.","commonSituations":"Running unmodified legacy V1.x configs on MMDet 2.x for a quick reproduction; old tutorial/notebook configs.","solutions":["Rename imgs_per_gpu to samples_per_gpu in the config to silence the notice.","Keep going as-is if you accept the compat behavior — training uses batch size N correctly.","Audit related legacy keys at the same time (total_epochs, workers_per_gpu naming, runner) to fully modernize the config.","Prefer split-specific settings (e.g. data = dict(train_dataloader=dict(samples_per_gpu=N))) in newer mmdet versions."],"exampleFix":"# before\ndata = dict(imgs_per_gpu=4, ...)\n# after\ndata = dict(samples_per_gpu=4, ...)","handlingStrategy":"validation","validationCode":"from mmcv import Config\n\ndef ensure_samples_per_gpu(cfg: Config) -> Config:\n    if 'imgs_per_gpu' in cfg.data and 'samples_per_gpu' not in cfg.data:\n        cfg.data.samples_per_gpu = cfg.data.pop('imgs_per_gpu')\n    return cfg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rename imgs_per_gpu to samples_per_gpu once and commit, to stop relying on compat shims.","Track which config keys your mmdet version expects via its official template configs."],"tags":["mmdetection","config","deprecation","migration","batch-size"],"backgroundTag":"deprecated-config-key","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}