{"record":{"id":"4295be16e5509296","repo":"open-mmlab/mmdetection","slug":"the-num-classes-should-be-1-in-rpn-but-get-rpn-4295be","errorCode":null,"errorMessage":"The `num_classes` should be 1 in RPN, but get {rpn_head_num_classes}, please set rpn_head.num_classes = 1 in your config file.","messagePattern":"The `num_classes` should be 1 in RPN, but get (.+?), please set rpn_head\\.num_classes = 1 in your config file\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/detectors/two_stage.py","lineNumber":48,"sourceCode":"                 data_preprocessor: OptConfigType = None,\n                 init_cfg: OptMultiConfig = None) -> None:\n        super().__init__(\n            data_preprocessor=data_preprocessor, init_cfg=init_cfg)\n        self.backbone = MODELS.build(backbone)\n\n        if neck is not None:\n            self.neck = MODELS.build(neck)\n\n        if rpn_head is not None:\n            rpn_train_cfg = train_cfg.rpn if train_cfg is not None else None\n            rpn_head_ = rpn_head.copy()\n            rpn_head_.update(train_cfg=rpn_train_cfg, test_cfg=test_cfg.rpn)\n            rpn_head_num_classes = rpn_head_.get('num_classes', None)\n            if rpn_head_num_classes is None:\n                rpn_head_.update(num_classes=1)\n            else:\n                if rpn_head_num_classes != 1:\n                    warnings.warn(\n                        'The `num_classes` should be 1 in RPN, but get '\n                        f'{rpn_head_num_classes}, please set '\n                        'rpn_head.num_classes = 1 in your config file.')\n                    rpn_head_.update(num_classes=1)\n            self.rpn_head = MODELS.build(rpn_head_)\n\n        if roi_head is not None:\n            # update train and test cfg here for now\n            # TODO: refactor assigner & sampler\n            rcnn_train_cfg = train_cfg.rcnn if train_cfg is not None else None\n            roi_head.update(train_cfg=rcnn_train_cfg)\n            roi_head.update(test_cfg=test_cfg.rcnn)\n            self.roi_head = MODELS.build(roi_head)\n\n        self.train_cfg = train_cfg\n        self.test_cfg = test_cfg\n\n    def _load_from_state_dict(self, state_dict: dict, prefix: str,","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/detectors/two_stage.py#L30-L66","documentation":"TwoStageDetector constructor warns when the rpn_head config explicitly sets num_classes != 1, then forces it to 1 (None defaults silently to 1). Same rationale as RPN: the RPN head is class-agnostic.","triggerScenarios":"Building a two-stage detector (Faster/Mask R-CNN etc.) whose rpn_head dict contains num_classes != 1.","commonSituations":"Config edits where a bbox_head's num_classes was duplicated into rpn_head; configs migrated from tutorials with wrong rpn settings.","solutions":["Change or remove rpn_head.num_classes so it equals 1","Put per-dataset num_classes only in roi_head.bbox_head"],"exampleFix":"# before\nrpn_head=dict(type='RPNHead', num_classes=80, ...)\n# after\nrpn_head=dict(type='RPNHead', ...)  # num_classes defaults to 1","handlingStrategy":"validation","validationCode":"rpn = cfg['model'].get('rpn_head')\nif rpn is not None:\n    rpn['num_classes'] = 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate two-stage configs: rpn_head.num_classes must be 1 or absent","Use config linting hooks before build_detector"],"tags":["mmdet","rpn","two-stage","config"],"backgroundTag":"invalid-config-value","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}