keras-team/keras · error · ValueError
Argument `size` must be a tuple of two elements (height…
Error message
Argument `size` must be a tuple of two elements (height, width). Received: size={size} What it means
Shape-specification guard in `resize` (NumPy backend): the target `size` must be exactly two elements — (height, width) — because the op resizes the two spatial dimensions of each image. Passing a scalar, a longer tuple (e.g. including channels or batch), or nested lists fails the length check and this error echoes the received value.
Solutions
- Pass size=(H, W) with exactly two integers
- Strip batch/channel entries from a full output shape: size = full_shape[1:3] for channels_last
- Replace a scalar target with an explicit pair, e.g. (size, size)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/numpy/ops/image.py:194 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/b9c93b8fe49a6c85.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/numpy/ops/image.py:194
):
data_format = standardize_data_format(data_format)
if interpolation not in RESIZE_INTERPOLATIONS:
raise ValueError(
"Invalid value for argument `interpolation`. Expected of one "
f"{RESIZE_INTERPOLATIONS}. Received: interpolation={interpolation}"
)
if fill_mode != "constant":
raise ValueError(
"Invalid value for argument `fill_mode`. Only `'constant'` "
f"is supported. Received: fill_mode={fill_mode}"
)
if pad_to_aspect_ratio and crop_to_aspect_ratio:
raise ValueError(
"Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` "
"can be `True`."
)
if not len(size) == 2:
raise ValueError(
"Argument `size` must be a tuple of two elements "
f"(height, width). Received: size={size}"
)
size = tuple(size)
target_height, target_width = size
if len(images.shape) == 4:
if data_format == "channels_last":
size = (images.shape[0],) + size + (images.shape[-1],)
else:
size = (images.shape[0], images.shape[1]) + size
elif len(images.shape) == 3:
if data_format == "channels_last":
size = size + (images.shape[-1],)
else:
size = (images.shape[0],) + size
else:
raise ValueError(
"Invalid images rank: expected rank 3 (single image) "View on GitHub (pinned to 7a34a03db6)