{"record":{"id":"51d0d35a4a17ac70","repo":"open-mmlab/mmdetection","slug":"got-imgs-per-gpu-cfg-data-imgs-per-gpu-and-sa","errorCode":null,"errorMessage":"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","messagePattern":"Got \"imgs_per_gpu\"=(.+?) and \"samples_per_gpu\"=(.+?), \"imgs_per_gpu\"=(.+?) is used in this experiments","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/utils/compat_config.py","lineNumber":43,"sourceCode":"            '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:\n        cfg.data['train_dataloader'] = ConfigDict()\n    if 'val_dataloader' not in cfg.data:\n        cfg.data['val_dataloader'] = ConfigDict()","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/utils/compat_config.py#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ndata = dict(imgs_per_gpu=2, samples_per_gpu=8, ...)\n# after\ndata = dict(samples_per_gpu=8, ...)","handlingStrategy":"validation","validationCode":"from mmcv import Config\n\ndef resolve_batch_keys(cfg: Config) -> Config:\n    data = cfg.data\n    if 'imgs_per_gpu' in data:\n        if 'samples_per_gpu' in data and data.imgs_per_gpu != data.samples_per_gpu:\n            raise ValueError(\n                f'Conflicting batch sizes: imgs_per_gpu={data.imgs_per_gpu} '\n                f'vs samples_per_gpu={data.samples_per_gpu}')\n        data.pop('imgs_per_gpu')\n    return cfg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["mmdetection","config","conflicting-keys","deprecation","batch-size"],"backgroundTag":"deprecated-config-key","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}