{"record":{"id":"887a4ecf2719b80c","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"expected-stages-out-channels-as-list-of-5-positive-887a4e","errorCode":null,"errorMessage":"expected stages_out_channels as list of 5 positive ints","messagePattern":"expected stages_out_channels as list of 5 positive ints","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pytorch_classification/mini_imagenet/model.py","lineNumber":95,"sourceCode":"            out = torch.cat((self.branch1(x), self.branch2(x)), dim=1)\n\n        out = channel_shuffle(out, 2)\n\n        return out\n\n\nclass ShuffleNetV2(nn.Module):\n    def __init__(self,\n                 stages_repeats: List[int],\n                 stages_out_channels: List[int],\n                 num_classes: int = 1000,\n                 inverted_residual: Callable[..., nn.Module] = InvertedResidual):\n        super(ShuffleNetV2, self).__init__()\n\n        if len(stages_repeats) != 3:\n            raise ValueError(\"expected stages_repeats as list of 3 positive ints\")\n        if len(stages_out_channels) != 5:\n            raise ValueError(\"expected stages_out_channels as list of 5 positive ints\")\n        self._stage_out_channels = stages_out_channels\n\n        # input RGB image\n        input_channels = 3\n        output_channels = self._stage_out_channels[0]\n\n        self.conv1 = nn.Sequential(\n            nn.Conv2d(input_channels, output_channels, kernel_size=3, stride=2, padding=1, bias=False),\n            nn.BatchNorm2d(output_channels),\n            nn.ReLU(inplace=True)\n        )\n        input_channels = output_channels\n\n        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)\n\n        # Static annotations for mypy\n        self.stage2: nn.Sequential\n        self.stage3: nn.Sequential","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_classification/mini_imagenet/model.py#L77-L113","documentation":"ShuffleNetV2's __init__ requires stages_out_channels to have exactly 5 entries: a 24-channel first-layer output plus one value per of the 4 stages. Any other length means the channel plan cannot be mapped onto the fixed stage structure, so a ValueError is raised.","triggerScenarios":"Calling ShuffleNetV2(stages_repeats=[...], stages_out_channels=[...]) with a stages_out_channels list whose len() != 5, e.g. [116, 232, 464, 1024] or [24, 116, 232, 464, 1024, 2048].","commonSituations":"Borrowing channel lists from other architectures (ResNet/EfficientNet have different stage counts), forgetting the leading 24, or appending an extra head channel.","solutions":["Pass exactly 5 channel values, e.g. [24, 116, 232, 464, 1024] for shufflenet_v2_x1_0.","Check the channel list source; make sure the initial 24-channel conv output is included.","Copy the known variants (0.5x: [24,48,96,192,1024]; 1.0x: [24,116,232,464,1024]; 1.5x: [24,176,352,704,1024]; 2.0x: [24,244,488,976,2048])."],"exampleFix":"// before\nmodel = ShuffleNetV2(stages_repeats=[4, 8, 4], stages_out_channels=[116, 232, 464, 1024], num_classes=100)\n// after\nmodel = ShuffleNetV2(stages_repeats=[4, 8, 4], stages_out_channels=[24, 116, 232, 464, 1024], num_classes=100)","handlingStrategy":"validation","validationCode":"assert len(stages_out_channels) == 5, f\"stages_out_channels must have 5 entries, got {len(stages_out_channels)}\"\nassert all(isinstance(c, int) and c > 0 for c in stages_out_channels), \"all channels must be positive ints\"","typeGuard":"def is_valid_stages_out_channels(v) -> bool:\n    return isinstance(v, (list, tuple)) and len(v) == 5 and all(isinstance(c, int) and c > 0 for c in v)","tryCatchPattern":"try:\n    model = ShuffleNetV2(stages_repeats=stages_repeats, stages_out_channels=stages_out_channels, num_classes=num_classes)\nexcept ValueError as e:\n    logging.error(\"bad ShuffleNetV2 channel config: %s\", e)\n    raise","preventionTips":["Include the leading 24-channel entry when writing channel lists","Use a named preset dict (e.g. SHUFFLENET_V2_X1_0) rather than raw lists","Add a config schema check (5 ints) before instantiating the model"],"tags":["python","pytorch","valueerror","model-config"],"backgroundTag":"invalid-model-config","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}