open-mmlab/mmdetection · error · ValueError
Only support 300 or 512 in SSDAnchorGenerator when not setti
Error message
Only support 300 or 512 in SSDAnchorGenerator when not setting min_sizes and max_sizes, got {self.input_size}. What it means
When min_sizes and max_sizes are not supplied, SSDAnchorGenerator can only auto-generate anchors for the two canonical SSD input sizes: 300 and 512. Any other input_size has no size preset and the constructor rejects it.
Source
Thrown at mmdet/models/task_modules/prior_generators/anchor_generator.py:577
raise ValueError(
'basesize_ratio_range[0] should be either 0.15'
'or 0.2 when input_size is 300, got '
f'{basesize_ratio_range[0]}.')
elif self.input_size == 512:
if basesize_ratio_range[0] == 0.1: # SSD512 COCO
min_sizes.insert(0, int(self.input_size * 4 / 100))
max_sizes.insert(0, int(self.input_size * 10 / 100))
elif basesize_ratio_range[0] == 0.15: # SSD512 VOC
min_sizes.insert(0, int(self.input_size * 7 / 100))
max_sizes.insert(0, int(self.input_size * 15 / 100))
else:
raise ValueError(
'When not setting min_sizes and max_sizes,'
'basesize_ratio_range[0] should be either 0.1'
'or 0.15 when input_size is 512, got'
f' {basesize_ratio_range[0]}.')
else:
raise ValueError(
'Only support 300 or 512 in SSDAnchorGenerator when '
'not setting min_sizes and max_sizes, '
f'got {self.input_size}.')
assert len(min_sizes) == len(max_sizes) == len(strides)
anchor_ratios = []
anchor_scales = []
for k in range(len(self.strides)):
scales = [1., np.sqrt(max_sizes[k] / min_sizes[k])]
anchor_ratio = [1.]
for r in ratios[k]:
anchor_ratio += [1 / r, r] # 4 or 6 ratio
anchor_ratios.append(torch.Tensor(anchor_ratio))
anchor_scales.append(torch.Tensor(scales))
self.base_sizes = min_sizes
self.scales = anchor_scalesView on GitHub (pinned to cfd5d3a985)
Solutions
- Set input_size to 300 or 512, or
- Provide explicit min_sizes and max_sizes lists computed for your resolution
- Check that input_size is a plain int (not a tuple like (512, 512)) which would fail the equality checks
Example fix
# before
anchor_generator=dict(type='SSDAnchorGenerator', input_size=640)
# after
anchor_generator=dict(
type='SSDAnchorGenerator', input_size=640,
min_sizes=[[21, 45], [102, 216], [267, 411], [399, 563], [534, 704], [669, 887]],
max_sizes=[[45, 99], [216, 336], [411, 549], [563, 721], [704, 880], [887, 1055]]) Defensive patterns
Strategy: validation
Validate before calling
ag = cfg['anchor_generator']
assert isinstance(ag.get('input_size'), int) and (ag['input_size'] in (300, 512) or ag.get('min_sizes')) Prevention
- Use int input_size, not tuples
- Provide min/max sizes for custom resolutions
When it happens
Trigger: SSDAnchorGenerator with input_size set to anything other than 300 or 512 (e.g. 320, 512x512 as a tuple, 800) while omitting min_sizes/max_sizes.
Common situations: Resizing SSD training to a non-standard resolution, or using a tuple input_size, without hand-specifying anchor sizes.
Related errors
- basesize_ratio_range[0] should be either 0.15or 0.2 when inp
- When not setting min_sizes and max_sizes,basesize_ratio_rang
- center_offset should be in range [0, 1], {center_offset} is
- Either scales or octave_base_scale with scales_per_octave sh
- LoadImageFromFile is not found in the test pipeline
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/14e1dbe8dea59e55.
Report an issue: GitHub.