open-mmlab/mmdetection · error · ValueError

Expect "arch" to be either a string or a dict, got {type(arc

Error message

Expect "arch" to be either a string or a dict, got {type(arch)}

What it means

RegNet.__init__ requires `arch` to be either a string key present in arch_settings ('regnetx_400mf', 'regnetx_800mf', etc.) or a dict containing w0, wa, wm, group_w, depth. Any other type (e.g. a list) raises ValueError. An unknown string instead fails the preceding assert.

Source

Thrown at mmdet/models/backbones/regnet.py:121

                 norm_cfg=dict(type='BN', requires_grad=True),
                 norm_eval=True,
                 dcn=None,
                 stage_with_dcn=(False, False, False, False),
                 plugins=None,
                 with_cp=False,
                 zero_init_residual=True,
                 pretrained=None,
                 init_cfg=None):
        super(ResNet, self).__init__(init_cfg)

        # Generate RegNet parameters first
        if isinstance(arch, str):
            assert arch in self.arch_settings, \
                f'"arch": "{arch}" is not one of the' \
                ' arch_settings'
            arch = self.arch_settings[arch]
        elif not isinstance(arch, dict):
            raise ValueError('Expect "arch" to be either a string '
                             f'or a dict, got {type(arch)}')

        widths, num_stages = self.generate_regnet(
            arch['w0'],
            arch['wa'],
            arch['wm'],
            arch['depth'],
        )
        # Convert to per stage format
        stage_widths, stage_blocks = self.get_stages_from_blocks(widths)
        # Generate group widths and bot muls
        group_widths = [arch['group_w'] for _ in range(num_stages)]
        self.bottleneck_ratio = [arch['bot_mul'] for _ in range(num_stages)]
        # Adjust the compatibility of stage_widths and group_widths
        stage_widths, group_widths = self.adjust_width_group(
            stage_widths, self.bottleneck_ratio, group_widths)

        # Group params by stage

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Use an exact arch_settings key, e.g. arch='regnetx_800mf'
  2. Or pass a full dict with keys w0, wa, wm, group_w, depth
  3. Check self.arch_settings in mmdet/models/backbones/regnet.py for supported names in your version

Example fix

// before
backbone=dict(type='RegNet', arch='regnetx-400mf')
// after
backbone=dict(type='RegNet', arch='regnetx_400mf')
Defensive patterns

Strategy: validation

Validate before calling

from mmdet.models.backbones.regnet import RegNet\nassert arch in RegNet.arch_settings or (isinstance(arch, dict) and {'w0','wa','wm','group_w','depth'} <= set(arch))

Type guard

def is_valid_regnet_arch(a):\n    return (isinstance(a, str) and a in RegNet.arch_settings) or (isinstance(a, dict) and {'w0','wa','wm','group_w','depth'} <= set(a))

Prevention

When it happens

Trigger: RegNet(arch=['regnetx_400mf']) (list instead of str); RegNet(arch='regnetx_1.6gf') with a typo'd/unsupported arch name (hits assert); RegNet(arch=dict(missing keys)).

Common situations: Typos in arch names in configs; loading arch from YAML/JSON where it parses as a non-str type; using a newer arch name unsupported by the installed mmdet version.

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


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/175aa4de0109c46c. Report an issue: GitHub.