keras-team/keras · error · ValueError
Invalid `size` argument. Expected a tuple of length 2 or 3.
Error message
Invalid `size` argument. Expected a tuple of length 2 or 3. Received: size={size} with length {len(size)} What it means
Error "Invalid `size` argument. Expected a tuple of length 2 or 3. Received: size={size} with length {len(size)}" thrown in keras-team/keras.
Source
Thrown at keras/src/ops/image.py:734
>>> patches = keras.ops.image.extract_patches(volumes, (3, 3, 3))
>>> patches.shape
(2, 3, 3, 3, 81)
>>> # 3D patches from single volume
>>> volume = np.random.random((10, 10, 10, 3)).astype("float32")
>>> patches = keras.ops.image.extract_patches(volume, (3, 3, 3))
>>> patches.shape
(3, 3, 3, 81)
"""
# Validate size argument
if not isinstance(size, int):
if not isinstance(size, (tuple, list)):
raise TypeError(
"Invalid `size` argument. Expected an int or a tuple. "
f"Received: size={size} of type {type(size).__name__}"
)
if len(size) not in (2, 3):
raise ValueError(
"Invalid `size` argument. Expected a tuple of length 2 or 3. "
f"Received: size={size} with length {len(size)}"
)
# 2D patch extraction (default)
if any_symbolic_tensors((images,)):
return ExtractPatches(
size=size,
strides=strides,
dilation_rate=dilation_rate,
padding=padding,
data_format=data_format,
).symbolic_call(images)
return _extract_patches(
images, size, strides, dilation_rate, padding, data_format=data_format
)
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/ops/image.py:734 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/ce5751ce15d7935f.
Report an issue: GitHub.