keras-team/keras · error · ValueError
The argument `strides` cannot contains 0. Received strides={
Error message
The argument `strides` cannot contains 0. Received strides={self.strides} What it means
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').
Source
Thrown at keras/src/layers/convolutional/base_depthwise_conv.py:145
self.bias_constraint = constraints.get(bias_constraint)
self.input_spec = InputSpec(min_ndim=self.rank + 2)
self.data_format = self.data_format
if self.depth_multiplier is not None and self.depth_multiplier <= 0:
raise ValueError(
"Invalid value for argument `depth_multiplier`. Expected a "
"strictly positive value. Received "
f"depth_multiplier={self.depth_multiplier}."
)
if not all(self.kernel_size):
raise ValueError(
"The argument `kernel_size` cannot contain 0. Received "
f"kernel_size={self.kernel_size}."
)
if not all(self.strides):
raise ValueError(
"The argument `strides` cannot contains 0. Received "
f"strides={self.strides}"
)
def build(self, input_shape):
if self.data_format == "channels_last":
channel_axis = -1
input_channel = input_shape[-1]
else:
channel_axis = 1
input_channel = input_shape[1]
self.input_spec = InputSpec(
min_ndim=self.rank + 2, axes={channel_axis: input_channel}
)
self.compute_output_shape(input_shape)
depthwise_shape = self.kernel_size + (
input_channel,
self.depth_multiplier,View on GitHub (pinned to 7a34a03db6)
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.
Example fix
# before keras.layers.DepthwiseConv2D(3, strides=(2, 0)) # after keras.layers.DepthwiseConv2D(3, strides=(2, 2))
Defensive patterns
Strategy: validation
Validate before calling
st = strides if isinstance(strides, (tuple, list)) else (strides,) assert all(s > 0 for s in st)
Type guard
def valid_strides(strides) -> bool:
st = strides if isinstance(strides, (tuple, list)) else (strides,)
return all(s > 0 for s in st) Prevention
- Never compute strides via integer division without a floor of 1
- Validate config before model construction
When it happens
Trigger: Constructing DepthwiseConv1D/2D/3D with strides containing a 0, e.g. strides=(2,0), often from a computed downsampling factor.
Common situations: Strides derived from arithmetic on input dims (stride = size // factor underflowing to 0); mis-pasting a kernel_size tuple into strides.
Related errors
- Invalid value for argument `depth_multiplier`. Expected a st
- The argument `kernel_size` cannot contain 0. Received kernel
- The argument `strides` cannot contains 0(s). Received: strid
- If using `weights="imagenet"` with `include_top=True`, `clas
- `strides > 1` not supported in conjunction with `dilation_ra
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/a10dc83eb0a36672.
Report an issue: GitHub.