{"record":{"id":"85bca32e93c90beb","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"expected-stages-repeats-as-list-of-3-positive-ints-85bca3","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/mini_imagenet/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/mini_imagenet/model.py#L75-L111","documentation":"ShuffleNetV2's __init__ validates its architecture hyperparameters before building layers. The stages_repeats argument must contain exactly 3 repeat counts (one per stage); passing a list of any other length makes the model structure ambiguous, so a ValueError is thrown immediately.","triggerScenarios":"Calling ShuffleNetV2(stages_repeats=[...], stages_out_channels=[...]) with a stages_repeats list whose len() != 3, e.g. [2, 4] or [2, 4, 8, 4].","commonSituations":"Hand-editing a config dict, copy-pasting a variant from another model family, or loading YAML/JSON hyperparameters where an extra element was added or one was omitted.","solutions":["Pass exactly 3 repeat counts, e.g. stages_repeats=[4, 8, 4] for shufflenet_v2_x1_0.","Check the source of your config (YAML/JSON/CLI) for extra or missing entries.","Copy the canonical values from a reference variant (0.5x: [4,8,4]; 1.0x: [4,8,4]; 1.5x: [4,8,4]; 2.0x: [4,8,4]) instead of inventing them."],"exampleFix":"// before\nmodel = ShuffleNetV2(stages_repeats=[4, 8], stages_out_channels=[24, 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_repeats) == 3, f\"stages_repeats must have 3 entries, got {len(stages_repeats)}\"\nassert all(isinstance(r, int) and r > 0 for r in stages_repeats), \"all repeats must be positive ints\"","typeGuard":"def is_valid_stages_repeats(v) -> bool:\n    return isinstance(v, (list, tuple)) and len(v) == 3 and all(isinstance(r, int) and r > 0 for r 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 config: %s\", e)\n    raise","preventionTips":["Keep architecture hyperparameters in a single validated config file","Copy canonical variant presets instead of hand-writing lists","Validate list lengths and element types at config load time"],"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"}