{"record":{"id":"9defe1bc1601781e","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"illegal-stride-value-9defe1","errorCode":null,"errorMessage":"illegal stride value.","messagePattern":"illegal stride value\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pytorch_segmentation/deeplab_v3/src/mobilenet_backbone.py","lineNumber":101,"sourceCode":"        self.out_c = self.adjust_channels(out_c, width_multi)\n        self.use_se = use_se\n        self.use_hs = activation == \"HS\"  # whether using h-swish activation\n        self.stride = stride\n        self.dilation = dilation\n\n    @staticmethod\n    def adjust_channels(channels: int, width_multi: float):\n        return _make_divisible(channels * width_multi, 8)\n\n\nclass InvertedResidual(nn.Module):\n    def __init__(self,\n                 cnf: InvertedResidualConfig,\n                 norm_layer: Callable[..., nn.Module]):\n        super(InvertedResidual, self).__init__()\n\n        if cnf.stride not in [1, 2]:\n            raise ValueError(\"illegal stride value.\")\n\n        self.use_res_connect = (cnf.stride == 1 and cnf.input_c == cnf.out_c)\n\n        layers: List[nn.Module] = []\n        activation_layer = nn.Hardswish if cnf.use_hs else nn.ReLU\n\n        # expand\n        if cnf.expanded_c != cnf.input_c:\n            layers.append(ConvBNActivation(cnf.input_c,\n                                           cnf.expanded_c,\n                                           kernel_size=1,\n                                           norm_layer=norm_layer,\n                                           activation_layer=activation_layer))\n\n        # depthwise\n        stride = 1 if cnf.dilation > 1 else cnf.stride\n        layers.append(ConvBNActivation(cnf.expanded_c,\n                                       cnf.expanded_c,","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_segmentation/deeplab_v3/src/mobilenet_backbone.py#L83-L119","documentation":"The InvertedResidual (MobileNetV3 block) only supports strides of 1 or 2, matching its skip-connection and downsampling design. InvertedResidualConfig-derived cnf.stride outside {1, 2} makes the block unconstructible, so __init__ raises ValueError('illegal stride value.').","triggerScenarios":"Building InvertedResidual with an InvertedResidualConfig whose stride is 0, 3, or any value other than 1 or 2 — e.g. hand-writing a custom inverted_residual_setting list.","commonSituations":"Custom/architecture-search configs with stride 3+; copy-paste editing a cnf entry and setting stride incorrectly; porting configs from other networks where larger strides are valid.","solutions":["Set each InvertedResidualConfig stride to 1 or 2.","If you need more downsampling, add extra blocks with stride 2 instead of one block with a larger stride.","Validate your custom config list before constructing the model (all strides in [1, 2])."],"exampleFix":"// before\nInvertedResidualConfig(16, 3, 64, 64, False, 'RE', 3, 1, 1)\n// after\nInvertedResidualConfig(16, 3, 64, 64, False, 'RE', 2, 1, 1)","handlingStrategy":"validation","validationCode":"assert all(cnf.stride in (1, 2) for cnf in inverted_residual_setting), \"stride must be 1 or 2\"","typeGuard":"def has_legal_strides(settings) -> bool:\n    return all(getattr(s, 'stride', None) in (1, 2) for s in settings)","tryCatchPattern":"try:\n    block = InvertedResidual(cnf, norm_layer)\nexcept ValueError as e:\n    logging.error(f\"{e}; stride={cnf.stride}\"); raise","preventionTips":["Build configs only via the provided preset builders","Downsample with multiple stride-2 blocks, never stride>2","Validate custom config lists before model construction"],"tags":["value-error","mobilenet","stride","configuration"],"backgroundTag":"illegal-stride-value","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}