keras-team/keras · error · ValueError
`patches` last dim ({static_flat}) is not divisible by prod(
Error message
`patches` last dim ({static_flat}) is not divisible by prod(size) ({pH * pW}). What it means
Error "`patches` last dim ({static_flat}) is not divisible by prod(size) ({pH * pW})." thrown in keras-team/keras.
Source
Thrown at keras/src/ops/image.py:1270
raise ValueError(
"`patches` has unexpected rank for 2D reconstruction. "
"Expected 3 (unbatched) or 4 (batched). "
f"Received shape: {patches.shape}"
)
_unbatched = False
if len(patches.shape) == 3:
_unbatched = True
patches = backend.numpy.expand_dims(patches, axis=0)
shp = ops.shape(patches)
B, gH, gW = shp[0], shp[1], shp[2]
static_flat = patches.shape[-1]
if static_flat is None:
C = shp[3] // (pH * pW)
else:
if static_flat % (pH * pW) != 0:
raise ValueError(
f"`patches` last dim ({static_flat}) is not divisible by "
f"prod(size) ({pH * pW})."
)
C = static_flat // (pH * pW)
x = backend.numpy.reshape(patches, (B, gH, gW, pH, pW, C))
x = backend.numpy.transpose(x, axes=(0, 1, 3, 2, 4, 5))
x = backend.numpy.reshape(x, (B, gH * pH, gW * pW, C))
if padding == "same":
static_gH = patches.shape[1]
static_gW = patches.shape[2]
if isinstance(static_gH, int) and not (
static_gH * pH - pH < H <= static_gH * pH
):
raise ValueError(
f"For `padding='same'`, `output_size` height ({H}) must "
f"be in the range ((gH-1)*pH, gH*pH], i.e. "View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/ops/image.py:1270 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/e621e1e775ce4da8.
Report an issue: GitHub.