open-mmlab/mmdetection · error · ValueError
Only square RoIs are supporeted in Grid R-CNN
Error message
Only square RoIs are supporeted in Grid R-CNN
What it means
Grid R-CNN's GridHead only supports square RoI feature sizes, so roi_feat_size must be an int (interpreted as both H and W). Passing a tuple like (7, 7) raises ValueError in __init__.
Source
Thrown at mmdet/models/roi_heads/mask_heads/grid_head.py:92
self.roi_feat_size = roi_feat_size
self.in_channels = in_channels
self.conv_kernel_size = conv_kernel_size
self.point_feat_channels = point_feat_channels
self.conv_out_channels = self.point_feat_channels * self.grid_points
self.class_agnostic = class_agnostic
self.conv_cfg = conv_cfg
self.norm_cfg = norm_cfg
if isinstance(norm_cfg, dict) and norm_cfg['type'] == 'GN':
assert self.conv_out_channels % norm_cfg['num_groups'] == 0
assert self.grid_points >= 4
self.grid_size = int(np.sqrt(self.grid_points))
if self.grid_size * self.grid_size != self.grid_points:
raise ValueError('grid_points must be a square number')
# the predicted heatmap is half of whole_map_size
if not isinstance(self.roi_feat_size, int):
raise ValueError('Only square RoIs are supporeted in Grid R-CNN')
self.whole_map_size = self.roi_feat_size * 4
# compute point-wise sub-regions
self.sub_regions = self.calc_sub_regions()
self.convs = []
for i in range(self.num_convs):
in_channels = (
self.in_channels if i == 0 else self.conv_out_channels)
stride = 2 if i == 0 else 1
padding = (self.conv_kernel_size - 1) // 2
self.convs.append(
ConvModule(
in_channels,
self.conv_out_channels,
self.conv_kernel_size,
stride=stride,
padding=padding,View on GitHub (pinned to cfd5d3a985)
Solutions
- Pass roi_feat_size as an int: roi_feat_size=7 (default)
- Keep the underlying RoIAlign output square (aligned H==W)
Example fix
# before roi_feat_size=(7, 7) # after roi_feat_size=7
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(cfg.get('roi_feat_size', 7), int), 'GridHead roi_feat_size must be int' Type guard
def is_int_roi_size(v) -> bool: return isinstance(v, int) and not isinstance(v, bool)
Prevention
- Pass roi_feat_size=7 (int) to GridHead
- Resist tuple sizes from other heads' docs
When it happens
Trigger: grid_head=dict(type='GridHead', roi_feat_size=(7, 7)) — supplying a rectangular size tuple as done in some other heads.
Common situations: Reusing bbox_head-style roi_feat_size tuples in a Grid R-CNN config; following generic docs that show tuple roi sizes.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- grid_points must be a square number
- LoadImageFromFile is not found in the test pipeline
- Visualization needs the "visualizer" termdefined in the conf
- config must be a filename or Config object, but got {type(co
- Unrecognized dataset: {dataset}
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/390d5acdc92d2dc6.
Report an issue: GitHub.