{"record":{"id":"ff0c7ec902fe60da","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"expected-stages-out-channels-as-list-of-5-positive","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/Test7_shufflenet/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/Test7_shufflenet/model.py#L77-L113","documentation":"ShuffleNetV2.__init__ requires stages_out_channels to contain exactly 5 entries (conv1 output plus the three stages plus the final conv5) and raises ValueError otherwise. Each entry fixes the output channel count of a corresponding layer group.","triggerScenarios":"Calling ShuffleNetV2 with stages_out_channels of length != 5 — e.g. [24, 116, 232, 464] (missing the last conv5 value) or [116, 232, 464, 1024] (only the stages).","commonSituations":"Defining a custom width variant and omitting the leading 24 (first conv) or trailing 1024 (last conv) value; truncating a copied preset list; confusing the channel list with the repeats list.","solutions":["Provide 5 channel counts, e.g. [24, 116, 232, 464, 1024] for the 1.0x model.","Use the provided presets ShuffleNetV2_x0_5/x1_0/x1_5/x2_0(num_classes=...) which hard-code valid lists.","Verify the order of positional args: stages_repeats first (3 items), stages_out_channels second (5 items)."],"exampleFix":"// before\nmodel = ShuffleNetV2(stages_repeats=[4, 8, 4], stages_out_channels=[116, 232, 464, 1024], num_classes=5)\n// after\nmodel = ShuffleNetV2(stages_repeats=[4, 8, 4], stages_out_channels=[24, 116, 232, 464, 1024], num_classes=5)","handlingStrategy":"validation","validationCode":"assert len(stages_out_channels) == 5, f\"stages_out_channels must have 5 ints, got {len(stages_out_channels)}\"\nmodel = ShuffleNetV2(stages_repeats=stages_repeats, stages_out_channels=stages_out_channels, num_classes=n)","typeGuard":"def valid_channels(c) -> bool:\n    return isinstance(c, list) and len(c) == 5 and all(isinstance(v, int) and v > 0 for v in c)","tryCatchPattern":"try:\n    model = ShuffleNetV2(stages_repeats=rep, stages_out_channels=ch, num_classes=n)\nexcept ValueError as e:\n    if \"stages_out_channels\" in str(e):\n        model = ShuffleNetV2_x1_0(num_classes=n)\n    else:\n        raise","preventionTips":["Copy full 5-element presets like [24, 116, 232, 464, 1024].","Use the factory functions for standard widths.","Validate list lengths before model construction."],"tags":["pytorch","shufflenetv2","valueerror","config","argument-validation"],"backgroundTag":"invalid-architecture-args","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}