{"record":{"id":"014bf459e9901744","repo":"open-mmlab/mmdetection","slug":"invalid-depth-depth-for-resnet","errorCode":null,"errorMessage":"invalid depth {depth} for resnet","messagePattern":"invalid depth (.+?) for resnet","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"mmdet/models/backbones/resnet.py","lineNumber":395,"sourceCode":"                 out_indices=(0, 1, 2, 3),\n                 style='pytorch',\n                 deep_stem=False,\n                 avg_down=False,\n                 frozen_stages=-1,\n                 conv_cfg=None,\n                 norm_cfg=dict(type='BN', requires_grad=True),\n                 norm_eval=True,\n                 dcn=None,\n                 stage_with_dcn=(False, False, False, False),\n                 plugins=None,\n                 with_cp=False,\n                 zero_init_residual=True,\n                 pretrained=None,\n                 init_cfg=None):\n        super(ResNet, self).__init__(init_cfg)\n        self.zero_init_residual = zero_init_residual\n        if depth not in self.arch_settings:\n            raise KeyError(f'invalid depth {depth} for resnet')\n\n        block_init_cfg = None\n        assert not (init_cfg and pretrained), \\\n            'init_cfg and pretrained cannot be specified at the same time'\n        if isinstance(pretrained, str):\n            warnings.warn('DeprecationWarning: pretrained is deprecated, '\n                          'please use \"init_cfg\" instead')\n            self.init_cfg = dict(type='Pretrained', checkpoint=pretrained)\n        elif pretrained is None:\n            if init_cfg is None:\n                self.init_cfg = [\n                    dict(type='Kaiming', layer='Conv2d'),\n                    dict(\n                        type='Constant',\n                        val=1,\n                        layer=['_BatchNorm', 'GroupNorm'])\n                ]\n                block = self.arch_settings[depth][0]","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/resnet.py#L377-L413","documentation":"ResNet.__init__ raises KeyError when `depth` is not one of the supported depths keyed in arch_settings (18, 34, 50, 101, 152). Each depth maps to (block, stage_blocks); an unsupported depth has no architecture definition.","triggerScenarios":"ResNet(depth=20), ResNet(depth=1010), or depth as a string like '50' (not in the int-keyed dict). Custom depths need a manual subclass that extends arch_settings.","commonSituations":"Typos in configs (depth=155); attempting ResNeSt/ResNeXt-style depths on plain ResNet; using a depth supported in newer mmdet (e.g. 200) on an older install.","solutions":["Use one of the supported depths: 18, 34, 50, 101, 152","For custom depths, subclass ResNet and add to arch_settings, e.g. arch_settings[100] = (Bottleneck, (3, 4, 23, 3))","Upgrade mmdet if the depth you need was added later"],"exampleFix":"// before\nbackbone=dict(type='ResNet', depth=20)\n// after\n# custom depth via subclass\nfrom mmdet.models.backbones.resnet import ResNet, Bottleneck\nclass ResNet100(ResNet):\n    arch_settings = {100: (Bottleneck, (3, 4, 23, 3))}\nbackbone=dict(type='ResNet100', depth=100)","handlingStrategy":"validation","validationCode":"from mmdet.models.backbones.resnet import ResNet\\nassert depth in ResNet.arch_settings, f'depth must be one of {list(ResNet.arch_settings)}'","typeGuard":"def is_valid_resnet_depth(d):\\n    from mmdet.models.backbones.resnet import ResNet\\n    return d in ResNet.arch_settings","tryCatchPattern":null,"preventionTips":["Check arch_settings of your installed mmdet version before choosing depth","Subclass to add custom depths"],"tags":["mmdet","resnet","depth","arch-settings","config"],"backgroundTag":"unsupported-variant-key","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}