{"record":{"id":"5acc7efd93bea2c3","repo":"open-mmlab/mmdetection","slug":"deprecationwarning-num-anchors-is-deprecated-f","errorCode":null,"errorMessage":"DeprecationWarning: `num_anchors` is deprecated, for consistency or also use `num_base_priors` instead","messagePattern":"DeprecationWarning: `num_anchors` is deprecated, for consistency or also use `num_base_priors` instead","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"mmdet/models/dense_heads/anchor_head.py","lineNumber":108,"sourceCode":"            if train_cfg.get('sampler', None) is not None:\n                self.sampler = TASK_UTILS.build(\n                    self.train_cfg['sampler'], default_args=dict(context=self))\n            else:\n                self.sampler = PseudoSampler(context=self)\n\n        self.fp16_enabled = False\n\n        self.prior_generator = TASK_UTILS.build(anchor_generator)\n\n        # Usually the numbers of anchors for each level are the same\n        # except SSD detectors. So it is an int in the most dense\n        # heads but a list of int in SSDHead\n        self.num_base_priors = self.prior_generator.num_base_priors[0]\n        self._init_layers()\n\n    @property\n    def num_anchors(self) -> int:\n        warnings.warn('DeprecationWarning: `num_anchors` is deprecated, '\n                      'for consistency or also use '\n                      '`num_base_priors` instead')\n        return self.prior_generator.num_base_priors[0]\n\n    @property\n    def anchor_generator(self) -> AnchorGenerator:\n        warnings.warn('DeprecationWarning: anchor_generator is deprecated, '\n                      'please use \"prior_generator\" instead')\n        return self.prior_generator\n\n    def _init_layers(self) -> None:\n        \"\"\"Initialize layers of the head.\"\"\"\n        self.conv_cls = nn.Conv2d(self.in_channels,\n                                  self.num_base_priors * self.cls_out_channels,\n                                  1)\n        reg_dim = self.bbox_coder.encode_size\n        self.conv_reg = nn.Conv2d(self.in_channels,\n                                  self.num_base_priors * reg_dim, 1)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/dense_heads/anchor_head.py#L90-L126","documentation":"The AnchorHead.num_anchors property is a deprecated alias for prior_generator.num_base_priors[0]. Accessing it emits a DeprecationWarning each time. mmdet renamed anchors to base_priors for consistency across heads.","triggerScenarios":"Reading head.num_anchors on AnchorHead (or subclasses like RPNHead, Faster R-CNN heads) in custom code or old plugins/tests.","commonSituations":"Custom dense heads, hooks, or visualization scripts written against older mmdet API; third-party projects relying on num_anchors.","solutions":["Replace head.num_anchors with head.num_base_priors","If a dependency triggers it and cannot be changed, suppress with warnings.filterwarnings ignoring the DeprecationWarning message"],"exampleFix":"# before\nn = self.bbox_head.num_anchors\n# after\nn = self.bbox_head.num_base_priors","handlingStrategy":"validation","validationCode":"assert hasattr(head, 'num_base_priors'), 'use num_base_priors'\nn = head.num_base_priors  # instead of head.num_anchors","typeGuard":"def get_num_priors(head):\n    if hasattr(head, 'num_base_priors'):\n        return head.num_base_priors\n    return head.num_anchors  # legacy fallback","tryCatchPattern":null,"preventionTips":["Target the num_base_priors attribute in custom code","Run tests with -W error::DeprecationWarning to catch old API usage early"],"tags":["mmdet","anchor-head","deprecation","rename"],"backgroundTag":"deprecated-argument-migration","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}