keras-team/keras · error · ValueError

The argument `strides` cannot contains 0(s). Received: strid

Error message

The argument `strides` cannot contains 0(s). Received: strides={self.strides}

What it means

Separable convolution strides must be positive in every spatial dimension; a 0 stride cannot slide the filter. __init__ rejects any strides sequence containing 0 (the message contains the typo 'cannot contains').

Source

Thrown at keras/src/layers/convolutional/base_separable_conv.py:154

                "Invalid value for argument `depth_multiplier`. Expected a "
                "strictly positive value. Received "
                f"depth_multiplier={self.depth_multiplier}."
            )

        if self.filters is not None and self.filters <= 0:
            raise ValueError(
                "Invalid value for argument `filters`. Expected a strictly "
                f"positive value. Received filters={self.filters}."
            )

        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(s). 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}
        )
        depthwise_kernel_shape = self.kernel_size + (
            input_channel,
            self.depth_multiplier,
        )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Set strides to positive integers (default 1).
  2. Validate dynamic strides: all(s > 0 for s in strides).
  3. Prefer strides=1 with pooling layers when unsure.

Example fix

# before
keras.layers.SeparableConv2D(32, 3, strides=(0, 2))

# after
keras.layers.SeparableConv2D(32, 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

When it happens

Trigger: Constructing SeparableConv1D/2D with a strides tuple containing 0, often from a computed downsampling factor or a mis-pasted tuple.

Common situations: Strides derived from input-size arithmetic that underflows to 0; reusing a kernel_size tuple as strides by mistake.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/da1e2a090dadb2be. Report an issue: GitHub.