keras-team/keras · error · ValueError

Invalid `strides` argument. Got

Error message

Invalid `strides` argument. Got: {strides}

What it means

Guard in _extract_patches_3d: after strides defaults to size and a scalar strides is expanded to a 3-tuple, the resulting strides sequence does not have one entry per spatial dimension, so per-axis stepping cannot be applied to the volume.

Solutions

  1. Pass an int (applied to all three axes) or a 3-tuple like (1, 2, 2)
  2. Leave strides=None to default to size (non-overlapping)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/ops/image.py:839 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at keras/src/ops/image.py:839

    dilation_rate=1,
    padding="valid",
    data_format=None,
):
    if isinstance(size, int):
        patch_d = patch_h = patch_w = size
    elif len(size) == 3:
        patch_d, patch_h, patch_w = size
    else:
        raise TypeError(
            "Invalid `size` argument. Expected an "
            f"int or a tuple of length 3. Received: size={size}"
        )
    if strides is None:
        strides = size
    if isinstance(strides, int):
        strides = (strides, strides, strides)
    if len(strides) != 3:
        raise ValueError(f"Invalid `strides` argument. Got: {strides}")
    data_format = backend.standardize_data_format(data_format)
    if data_format == "channels_last":
        channels_in = volumes.shape[-1]
    elif data_format == "channels_first":
        channels_in = volumes.shape[-4]
    out_dim = patch_d * patch_w * patch_h * channels_in
    kernel = backend.numpy.eye(out_dim, dtype=volumes.dtype)
    kernel = backend.numpy.reshape(
        kernel, (patch_d, patch_h, patch_w, channels_in, out_dim)
    )
    _unbatched = False
    if len(volumes.shape) == 4:
        _unbatched = True
        volumes = backend.numpy.expand_dims(volumes, axis=0)
    patches = backend.nn.conv(
        inputs=volumes,
        kernel=kernel,
        strides=strides,

View on GitHub (pinned to 7a34a03db6)