{"record":{"id":"108a52de9d0fb94e","repo":"open-mmlab/mmdetection","slug":"num-branches-num-branches-num-blocks-len-nu","errorCode":null,"errorMessage":"NUM_BRANCHES({num_branches}) != NUM_BLOCKS({len(num_blocks)})","messagePattern":"NUM_BRANCHES\\((.+?)\\) != NUM_BLOCKS\\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/models/backbones/hrnet.py","lineNumber":54,"sourceCode":"\n        self.in_channels = in_channels\n        self.num_branches = num_branches\n\n        self.multiscale_output = multiscale_output\n        self.norm_cfg = norm_cfg\n        self.conv_cfg = conv_cfg\n        self.with_cp = with_cp\n        self.branches = self._make_branches(num_branches, blocks, num_blocks,\n                                            num_channels)\n        self.fuse_layers = self._make_fuse_layers()\n        self.relu = nn.ReLU(inplace=False)\n\n    def _check_branches(self, num_branches, num_blocks, in_channels,\n                        num_channels):\n        if num_branches != len(num_blocks):\n            error_msg = f'NUM_BRANCHES({num_branches}) ' \\\n                        f'!= NUM_BLOCKS({len(num_blocks)})'\n            raise ValueError(error_msg)\n\n        if num_branches != len(num_channels):\n            error_msg = f'NUM_BRANCHES({num_branches}) ' \\\n                        f'!= NUM_CHANNELS({len(num_channels)})'\n            raise ValueError(error_msg)\n\n        if num_branches != len(in_channels):\n            error_msg = f'NUM_BRANCHES({num_branches}) ' \\\n                        f'!= NUM_INCHANNELS({len(in_channels)})'\n            raise ValueError(error_msg)\n\n    def _make_one_branch(self,\n                         branch_index,\n                         block,\n                         num_blocks,\n                         num_channels,\n                         stride=1):\n        downsample = None","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/hrnet.py#L36-L72","documentation":"HRNet's _check_branches validates per-stage config consistency: num_branches must equal len(num_blocks) for each stage in extra. A mismatch means the stage definition is internally inconsistent and raises ValueError with this exact message.","triggerScenarios":"In extra['stage2'], setting num_branches=2 but num_blocks=[4,4,4] (len 3); editing an HRNet config's stage dict and forgetting to keep list lengths equal to num_branches.","commonSituations":"Customizing HRNet-W18/W32/W48 configs; reducing branch counts for ablation while leaving num_blocks lists unchanged; typos when hand-editing nested stage dicts.","solutions":["For each stage in extra, make len(num_blocks) == num_branches (e.g. num_branches=2 with num_blocks=[4,4])","Start from an official hrnet config and change only one field at a time","Also verify num_channels and in_channels lengths match num_branches (they are checked next)"],"exampleFix":"# before\nextra=dict(stage2=dict(num_branches=2, num_blocks=[4,4,4], num_channels=[18,36])))\n# after\nextra=dict(stage2=dict(num_branches=2, num_blocks=[4,4], num_channels=[18,36])))","handlingStrategy":"validation","validationCode":"for stage in extra.values():\n    assert stage['num_branches'] == len(stage['num_blocks']), 'num_blocks length must equal num_branches'","typeGuard":"def stage_consistent(stage: dict) -> bool:\n    n = stage['num_branches']\n    return len(stage['num_blocks']) == n and len(stage['num_channels']) == n and len(stage['in_channels']) == n","tryCatchPattern":null,"preventionTips":["Edit only one field per change in HRNet stage dicts","Keep all four per-stage lists length == num_branches","Start from official HRNet configs"],"tags":["mmdet","hrnet","backbone","config-validation"],"backgroundTag":null,"analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}