{"record":{"id":"bfd17d669db548c5","repo":"open-mmlab/mmdetection","slug":"single-level-grid-anchors-would-be-deprecated","errorCode":null,"errorMessage":"``single_level_grid_anchors`` would be deprecated soon. Please use ``single_level_grid_priors`` ","messagePattern":"``single_level_grid_anchors`` would be deprecated soon\\. Please use ``single_level_grid_priors`` ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/task_modules/prior_generators/anchor_generator.py","lineNumber":392,"sourceCode":"                                  device: DeviceType = 'cuda') -> Tensor:\n        \"\"\"Generate grid anchors of a single level.\n\n        Note:\n            This function is usually called by method ``self.grid_anchors``.\n\n        Args:\n            base_anchors (torch.Tensor): The base anchors of a feature grid.\n            featmap_size (tuple[int]): Size of the feature maps.\n            stride (tuple[int, int]): Stride of the feature map in order\n                (w, h). Defaults to (16, 16).\n            device (str | torch.device): Device the tensor will be put on.\n                Defaults to 'cuda'.\n\n        Returns:\n            torch.Tensor: Anchors in the overall feature maps.\n        \"\"\"\n\n        warnings.warn(\n            '``single_level_grid_anchors`` would be deprecated soon. '\n            'Please use ``single_level_grid_priors`` ')\n\n        # keep featmap_size as Tensor instead of int, so that we\n        # can convert to ONNX correctly\n        feat_h, feat_w = featmap_size\n        shift_x = torch.arange(0, feat_w, device=device) * stride[0]\n        shift_y = torch.arange(0, feat_h, device=device) * stride[1]\n\n        shift_xx, shift_yy = self._meshgrid(shift_x, shift_y)\n        shifts = torch.stack([shift_xx, shift_yy, shift_xx, shift_yy], dim=-1)\n        shifts = shifts.type_as(base_anchors)\n        # first feat_w elements correspond to the first row of shifts\n        # add A anchors (1, A, 4) to K shifts (K, 1, 4) to get\n        # shifted anchors (K, A, 4), reshape to (K*A, 4)\n\n        all_anchors = base_anchors[None, :, :] + shifts[:, None, :]\n        all_anchors = all_anchors.view(-1, 4)","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/task_modules/prior_generators/anchor_generator.py#L374-L410","documentation":"Deprecation warning from AnchorGenerator.single_level_grid_anchors: the per-level anchors API is superseded by single_level_grid_priors. It is still called internally by grid_anchors but direct calls will break once removed.","triggerScenarios":"Directly invoking single_level_grid_anchors(featmap_size, stride, device) in a custom head or test; also triggered transitively through grid_anchors.","commonSituations":"Custom anchor-based heads computing anchors level by level; code migration during the anchors→priors rename.","solutions":["Call single_level_grid_priors(...) instead","Prefer grid_priors for whole-pyramid generation rather than per-level calls","Update transitive callers to the priors API to silence both warnings"],"exampleFix":"# before\nanchors = generator.single_level_grid_anchors(featmap_size, stride, device=device)\n# after\npriors = generator.single_level_grid_priors(featmap_size, stride, device=device)","handlingStrategy":"type-guard","validationCode":"assert hasattr(gen, 'single_level_grid_priors'), 'use single_level_grid_priors'","typeGuard":"def has_priors_api(gen) -> bool:\n    return hasattr(gen, 'single_level_grid_priors')","tryCatchPattern":null,"preventionTips":["Call single_level_grid_priors in custom heads","Avoid per-level anchor code; prefer grid_priors"],"tags":["mmdet","deprecation","anchor-generator","priors"],"backgroundTag":"deprecated-api-renamed","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}