keras-team/keras · error · ValueError
`strides` must be a tuple of 2 integers.
Error message
`strides` must be a tuple of 2 integers.
What it means
In the deprecated legacy pool2d, `strides` must be a 2-tuple of integers matching the 2D pooling semantics (height and width strides). A tuple/list of any other length triggers this ValueError. This is a legacy API guard; prefer keras.layers.Pooling instead.
Solutions
- Pass a 2-element tuple, e.g. strides=(2, 2)
- Prefer the modern MaxPooling2D/AveragePooling2D layers over the legacy helper
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/legacy/backend.py:1101 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/8f445077b0e587a5.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/legacy/backend.py:1101
@keras_export("keras._legacy.backend.pool2d")
def pool2d(
x,
pool_size,
strides=(1, 1),
padding="valid",
data_format=None,
pool_mode="max",
):
"""DEPRECATED."""
if data_format is None:
data_format = backend.image_data_format()
if data_format not in {"channels_first", "channels_last"}:
raise ValueError(f"Unknown data_format: {data_format}")
if len(pool_size) != 2:
raise ValueError("`pool_size` must be a tuple of 2 integers.")
if len(strides) != 2:
raise ValueError("`strides` must be a tuple of 2 integers.")
x, tf_data_format = _preprocess_conv2d_input(x, data_format)
padding = _preprocess_padding(padding)
if tf_data_format == "NHWC":
strides = (1,) + strides + (1,)
pool_size = (1,) + pool_size + (1,)
else:
strides = (1, 1) + strides
pool_size = (1, 1) + pool_size
if pool_mode == "max":
x = tf.compat.v1.nn.max_pool(
x, pool_size, strides, padding=padding, data_format=tf_data_format
)
elif pool_mode == "avg":
x = tf.compat.v1.nn.avg_pool(
x, pool_size, strides, padding=padding, data_format=tf_data_format
)View on GitHub (pinned to 7a34a03db6)