open-mmlab/mmdetection · warning
``grid_anchors`` would be deprecated soon. Please use ``grid
Error message
``grid_anchors`` would be deprecated soon. Please use ``grid_priors``
What it means
Deprecation warning from AnchorGenerator.grid_anchors: the anchors-named API is being replaced by the priors API. grid_anchors(featmap_sizes, device) still works (delegating to single_level_grid_anchors) but grid_priors should be used instead.
Source
Thrown at mmdet/models/task_modules/prior_generators/anchor_generator.py:356
def grid_anchors(self,
featmap_sizes: List[Tuple],
device: DeviceType = 'cuda') -> List[Tensor]:
"""Generate grid anchors in multiple feature levels.
Args:
featmap_sizes (list[tuple]): List of feature map sizes in
multiple feature levels.
device (str | torch.device): Device where the anchors will be
put on.
Return:
list[torch.Tensor]: Anchors in multiple feature levels. \
The sizes of each tensor should be [N, 4], where \
N = width * height * num_base_anchors, width and height \
are the sizes of the corresponding feature level, \
num_base_anchors is the number of anchors for that level.
"""
warnings.warn('``grid_anchors`` would be deprecated soon. '
'Please use ``grid_priors`` ')
assert self.num_levels == len(featmap_sizes)
multi_level_anchors = []
for i in range(self.num_levels):
anchors = self.single_level_grid_anchors(
self.base_anchors[i].to(device),
featmap_sizes[i],
self.strides[i],
device=device)
multi_level_anchors.append(anchors)
return multi_level_anchors
def single_level_grid_anchors(self,
base_anchors: Tensor,
featmap_size: Tuple[int, int],
stride: Tuple[int, int] = (16, 16),
device: DeviceType = 'cuda') -> Tensor:View on GitHub (pinned to cfd5d3a985)
Solutions
- Replace grid_anchors(...) with grid_priors(...) (same signature semantics)
- Rename any cached attribute usage (e.g. prior caching) accordingly
- Update tests referencing grid_anchors
Example fix
# before anchors = self.anchor_generator.grid_anchors(featmap_sizes, device=device) # after priors = self.prior_generator.grid_priors(featmap_sizes, device=device)
Defensive patterns
Strategy: type-guard
Validate before calling
assert hasattr(gen, 'grid_priors'), 'generator lacks grid_priors; upgrade mmdet'
Type guard
def has_priors_api(gen) -> bool:
return hasattr(gen, 'grid_priors') and callable(gen.grid_priors) Prevention
- Feature-detect grid_priors before calling
- Write heads against the priors API, not anchors
When it happens
Trigger: Calling anchor_generator.grid_anchors(featmap_sizes, device=...); many old unit tests (test_sparse_prior, test_strides, test_retina_anchor, SSD/YOLO anchor tests) and legacy dense heads call it.
Common situations: Custom dense heads or tests written against the pre-rename API; mmdet refactored 'anchors' to generic 'priors' to cover non-anchor detectors.
Related errors
- ``single_level_grid_anchors`` would be deprecated soon. Plea
- ``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/786bde9a424d0c50.
Report an issue: GitHub.