{"record":{"id":"3988f7c5e13ec620","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"expected-stages-repeats-as-list-of-3-positive-ints","errorCode":null,"errorMessage":"expected stages_repeats as list of 3 positive ints","messagePattern":"expected stages_repeats as list of 3 positive ints","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pytorch_classification/Test7_shufflenet/model.py","lineNumber":93,"sourceCode":"            out = torch.cat((x1, self.branch2(x2)), dim=1)\n        else:\n            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","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_classification/Test7_shufflenet/model.py#L75-L111","documentation":"ShuffleNetV2.__init__ asserts that stages_repeats is a list of exactly 3 entries (one repeat count per stage2/3/4) and raises ValueError with this message when len(stages_repeats) != 3. The architecture is fixed to three inverted-residual stages.","triggerScenarios":"Calling ShuffleNetV2(stages_repeats=..., stages_out_channels=...) with a list of length other than 3 — e.g. [4] , [4, 8], [4, 8, 4, 4], or forgetting the argument so a wrong default/None is used.","commonSituations":"Building a custom variant of ShuffleNetV2 with extra or fewer stages; misreading the preset tables and copying a 4-element list; passing stages_out_channels by mistake into the stages_repeats slot.","solutions":["Pass exactly 3 repeat counts, e.g. stages_repeats=[4, 8, 4] (1.0x preset).","Use the provided factory functions ShuffleNetV2_x0_5/x1_0/x1_5/x2_0(num_classes=...) instead of calling ShuffleNetV2 directly.","Swap arguments if you passed them in the wrong order — repeats is 3 elements, channels is 5."],"exampleFix":"// before\nmodel = ShuffleNetV2(stages_repeats=[4, 8, 4, 4], stages_out_channels=[24, 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_repeats) == 3, f\"stages_repeats must have 3 ints, got {len(stages_repeats)}\"\nmodel = ShuffleNetV2(stages_repeats=stages_repeats, stages_out_channels=stages_out_channels, num_classes=n)","typeGuard":"def valid_repeats(r) -> bool:\n    return isinstance(r, list) and len(r) == 3 and all(isinstance(v, int) and v > 0 for v in r)","tryCatchPattern":"try:\n    model = ShuffleNetV2(stages_repeats=rep, stages_out_channels=ch, num_classes=n)\nexcept ValueError as e:\n    if \"stages_repeats\" in str(e):\n        model = ShuffleNetV2_x1_0(num_classes=n)\n    else:\n        raise","preventionTips":["Prefer ShuffleNetV2_x0_5/x1_0/x1_5/x2_0 factories over direct construction.","Check argument order: repeats (3) before channels (5).","Validate list lengths before constructing the model."],"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"}