open-mmlab/mmdetection · warning
``single_level_grid_anchors`` would be deprecated soon. Plea
Error message
``single_level_grid_anchors`` would be deprecated soon. Please use ``single_level_grid_priors``
What it means
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.
Source
Thrown at mmdet/models/task_modules/prior_generators/anchor_generator.py:392
device: DeviceType = 'cuda') -> Tensor:
"""Generate grid anchors of a single level.
Note:
This function is usually called by method ``self.grid_anchors``.
Args:
base_anchors (torch.Tensor): The base anchors of a feature grid.
featmap_size (tuple[int]): Size of the feature maps.
stride (tuple[int, int]): Stride of the feature map in order
(w, h). Defaults to (16, 16).
device (str | torch.device): Device the tensor will be put on.
Defaults to 'cuda'.
Returns:
torch.Tensor: Anchors in the overall feature maps.
"""
warnings.warn(
'``single_level_grid_anchors`` would be deprecated soon. '
'Please use ``single_level_grid_priors`` ')
# keep featmap_size as Tensor instead of int, so that we
# can convert to ONNX correctly
feat_h, feat_w = featmap_size
shift_x = torch.arange(0, feat_w, device=device) * stride[0]
shift_y = torch.arange(0, feat_h, device=device) * stride[1]
shift_xx, shift_yy = self._meshgrid(shift_x, shift_y)
shifts = torch.stack([shift_xx, shift_yy, shift_xx, shift_yy], dim=-1)
shifts = shifts.type_as(base_anchors)
# first feat_w elements correspond to the first row of shifts
# add A anchors (1, A, 4) to K shifts (K, 1, 4) to get
# shifted anchors (K, A, 4), reshape to (K*A, 4)
all_anchors = base_anchors[None, :, :] + shifts[:, None, :]
all_anchors = all_anchors.view(-1, 4)View on GitHub (pinned to cfd5d3a985)
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
Example fix
# before anchors = generator.single_level_grid_anchors(featmap_size, stride, device=device) # after priors = generator.single_level_grid_priors(featmap_size, stride, device=device)
Defensive patterns
Strategy: type-guard
Validate before calling
assert hasattr(gen, 'single_level_grid_priors'), 'use single_level_grid_priors'
Type guard
def has_priors_api(gen) -> bool:
return hasattr(gen, 'single_level_grid_priors') Prevention
- Call single_level_grid_priors in custom heads
- Avoid per-level anchor code; prefer grid_priors
When it happens
Trigger: Directly invoking single_level_grid_anchors(featmap_size, stride, device) in a custom head or test; also triggered transitively through grid_anchors.
Common situations: Custom anchor-based heads computing anchors level by level; code migration during the anchors→priors rename.
Related errors
- ``grid_anchors`` would be deprecated soon. Please use ``grid
- ``build_anchor_generator`` would be deprecated soon, please
- DeprecationWarning: bboxes is deprecated, please use "priors
- DeprecationWarning: pos_bboxes is deprecated, please use "po
- DeprecationWarning: neg_bboxes is deprecated, please use "ne
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/bfd17d669db548c5.
Report an issue: GitHub.