open-mmlab/mmdetection · error · ValueError
out_indices must be a subset of range(0, 8). But received {o
Error message
out_indices must be a subset of range(0, 8). But received {out_indices} What it means
MobileNetV2.__init__ validates out_indices: every element must be an integer in 0..7 (the backbone has 8 stages of inverted residual blocks). Passing indices outside that set raises ValueError because no feature map exists for them.
Source
Thrown at mmdet/models/backbones/mobilenet_v2.py:82
warnings.warn('DeprecationWarning: pretrained is deprecated, '
'please use "init_cfg" instead')
self.init_cfg = dict(type='Pretrained', checkpoint=pretrained)
elif pretrained is None:
if init_cfg is None:
self.init_cfg = [
dict(type='Kaiming', layer='Conv2d'),
dict(
type='Constant',
val=1,
layer=['_BatchNorm', 'GroupNorm'])
]
else:
raise TypeError('pretrained must be a str or None')
self.widen_factor = widen_factor
self.out_indices = out_indices
if not set(out_indices).issubset(set(range(0, 8))):
raise ValueError('out_indices must be a subset of range'
f'(0, 8). But received {out_indices}')
if frozen_stages not in range(-1, 8):
raise ValueError('frozen_stages must be in range(-1, 8). '
f'But received {frozen_stages}')
self.out_indices = out_indices
self.frozen_stages = frozen_stages
self.conv_cfg = conv_cfg
self.norm_cfg = norm_cfg
self.act_cfg = act_cfg
self.norm_eval = norm_eval
self.with_cp = with_cp
self.in_channels = make_divisible(32 * widen_factor, 8)
self.conv1 = ConvModule(
in_channels=3,
out_channels=self.in_channels,View on GitHub (pinned to cfd5d3a985)
Solutions
- Restrict out_indices to values within range(0, 8), e.g. (1, 2, 4, 7)
- Count the MobileNetV2 stages for your widen_factor config and pick valid exit points
- Match the number of out_indices to what the downstream neck (FPN) expects
Example fix
// before backbone=dict(type='MobileNetV2', out_indices=(0, 1, 2, 3, 4, 5, 6, 7, 8)) // after backbone=dict(type='MobileNetV2', out_indices=(1, 2, 4, 7))
Defensive patterns
Strategy: validation
Validate before calling
assert set(out_indices).issubset(set(range(0, 8))), 'out_indices must be within 0..7'
Prevention
- Check backbone stage count before setting out_indices
- Keep out_indices consistent with the neck's in_channels list
When it happens
Trigger: MobileNetV2(out_indices=(8,)) or out_indices=[-1, 4] or out_indices=(0, 1, 2, 3, 4, 5, 6, 7, 8); any subset not within set(range(0, 8)).
Common situations: Configuring FPN/neck outputs to take extra feature levels; copying out_indices from another backbone (e.g. ResNet depth-50 with 4 stages) into MobileNetV2; off-by-one when listing stages.
Related errors
- metric must be a list or a str.
- metrics {iou_metrics} is not supported. Only supports mIoU/m
- the item in out_indices must in range(0, {len(self.layer_set
- pretrained must be a str or None
- frozen_stages must be in range(-1, 8). But received {frozen_
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/2981b4eae86eff16.
Report an issue: GitHub.