{"record":{"id":"a10dc83eb0a36672","repo":"keras-team/keras","slug":"the-argument-strides-cannot-contains-0-received","errorCode":null,"errorMessage":"The argument `strides` cannot contains 0. Received strides={self.strides}","messagePattern":"The argument `strides` cannot contains 0\\. Received strides=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/convolutional/base_depthwise_conv.py","lineNumber":145,"sourceCode":"        self.bias_constraint = constraints.get(bias_constraint)\n        self.input_spec = InputSpec(min_ndim=self.rank + 2)\n        self.data_format = self.data_format\n\n        if self.depth_multiplier is not None and self.depth_multiplier <= 0:\n            raise ValueError(\n                \"Invalid value for argument `depth_multiplier`. Expected a \"\n                \"strictly positive value. Received \"\n                f\"depth_multiplier={self.depth_multiplier}.\"\n            )\n\n        if not all(self.kernel_size):\n            raise ValueError(\n                \"The argument `kernel_size` cannot contain 0. Received \"\n                f\"kernel_size={self.kernel_size}.\"\n            )\n\n        if not all(self.strides):\n            raise ValueError(\n                \"The argument `strides` cannot contains 0. Received \"\n                f\"strides={self.strides}\"\n            )\n\n    def build(self, input_shape):\n        if self.data_format == \"channels_last\":\n            channel_axis = -1\n            input_channel = input_shape[-1]\n        else:\n            channel_axis = 1\n            input_channel = input_shape[1]\n        self.input_spec = InputSpec(\n            min_ndim=self.rank + 2, axes={channel_axis: input_channel}\n        )\n        self.compute_output_shape(input_shape)\n        depthwise_shape = self.kernel_size + (\n            input_channel,\n            self.depth_multiplier,","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/convolutional/base_depthwise_conv.py#L127-L163","documentation":"Depthwise convolution strides must be positive in every spatial dimension; a 0 stride is meaningless for sliding a filter. The constructor rejects any strides tuple containing 0 (the message contains the grammar typo 'cannot contains').","triggerScenarios":"Constructing DepthwiseConv1D/2D/3D with strides containing a 0, e.g. strides=(2,0), often from a computed downsampling factor.","commonSituations":"Strides derived from arithmetic on input dims (stride = size // factor underflowing to 0); mis-pasting a kernel_size tuple into strides.","solutions":["Set strides to positive integers in every dimension (default 1).","Validate all(s > 0 for s in strides) before layer creation.","Prefer strides=1 with pooling when downsampling intent is unclear."],"exampleFix":"# before\nkeras.layers.DepthwiseConv2D(3, strides=(2, 0))\n\n# after\nkeras.layers.DepthwiseConv2D(3, strides=(2, 2))","handlingStrategy":"validation","validationCode":"st = strides if isinstance(strides, (tuple, list)) else (strides,)\nassert all(s > 0 for s in st)","typeGuard":"def valid_strides(strides) -> bool:\n    st = strides if isinstance(strides, (tuple, list)) else (strides,)\n    return all(s > 0 for s in st)","tryCatchPattern":null,"preventionTips":["Never compute strides via integer division without a floor of 1","Validate config before model construction"],"tags":["keras","depthwise-conv","strides","invalid-arguments"],"backgroundTag":"invalid-layer-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}