open-mmlab/mmdetection · error · ValueError
basesize_ratio_range[0] should be either 0.15or 0.2 when inp
Error message
basesize_ratio_range[0] should be either 0.15or 0.2 when input_size is 300, got {basesize_ratio_range[0]}. What it means
SSDAnchorGenerator auto-computes SSD anchor sizes when min_sizes/max_sizes are not provided. For input_size=300 it only knows two presets selected by the first element of basesize_ratio_range: 0.15 (COCO) or 0.2 (VOC). Any other ratio value has no preset so the constructor rejects it.
Source
Thrown at mmdet/models/task_modules/prior_generators/anchor_generator.py:559
# calculate anchor ratios and sizes
min_ratio, max_ratio = basesize_ratio_range
min_ratio = int(min_ratio * 100)
max_ratio = int(max_ratio * 100)
step = int(np.floor(max_ratio - min_ratio) / (self.num_levels - 2))
min_sizes = []
max_sizes = []
for ratio in range(int(min_ratio), int(max_ratio) + 1, step):
min_sizes.append(int(self.input_size * ratio / 100))
max_sizes.append(int(self.input_size * (ratio + step) / 100))
if self.input_size == 300:
if basesize_ratio_range[0] == 0.15: # SSD300 COCO
min_sizes.insert(0, int(self.input_size * 7 / 100))
max_sizes.insert(0, int(self.input_size * 15 / 100))
elif basesize_ratio_range[0] == 0.2: # SSD300 VOC
min_sizes.insert(0, int(self.input_size * 10 / 100))
max_sizes.insert(0, int(self.input_size * 20 / 100))
else:
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(View on GitHub (pinned to cfd5d3a985)
Solutions
- Set basesize_ratio_range to (0.2, 0.95) for SSD300 VOC or (0.15, 0.75) for SSD300 COCO
- Or provide explicit min_sizes and max_sizes lists so the auto-computation branch is skipped
- If you need a custom ratio at 300, compute your own min/max size lists and pass them directly
Example fix
# before
anchor_generator=dict(
type='SSDAnchorGenerator',
input_size=300,
basesize_ratio_range=(0.1, 0.9))
# after
anchor_generator=dict(
type='SSDAnchorGenerator',
input_size=300,
basesize_ratio_range=(0.2, 0.95)) # SSD300 VOC Defensive patterns
Strategy: validation
Validate before calling
bsrr = cfg['anchor_generator']['basesize_ratio_range'][0]
assert cfg['anchor_generator'].get('input_size') != 300 or bsrr in (0.15, 0.2) or 'min_sizes' in cfg['anchor_generator'] Prevention
- Keep SSD300 preset ratios documented next to configs
- Always pass explicit min_sizes/max_sizes when deviating from presets
When it happens
Trigger: Building SSDAnchorGenerator (or an SSD/Retina SSD config) with input_size=300, min_sizes/max_sizes unset, and basesize_ratio_range whose first element is not exactly 0.15 or 0.2 (e.g. 0.1 or 0.25).
Common situations: Copying an SSD512 config (ratio 0.1) and changing input_size to 300, or tweaking basesize_ratio_range for experiments without supplying explicit min_sizes/max_sizes.
Related errors
- When not setting min_sizes and max_sizes,basesize_ratio_rang
- Only support 300 or 512 in SSDAnchorGenerator when not setti
- Invalid scale {scale}, must be positive.
- Scale must be a number or tuple of int, but got {type(scale)
- Invalid crop_type {crop_type}.
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/3e0d2298ee9596d9.
Report an issue: GitHub.