keras-team/keras · error · ValueError
For `padding='same'`, `output_size` {dim_name} ({o}) must be
Error message
For `padding='same'`, `output_size` {dim_name} ({o}) must be in the range ((g-1)*p, g*p], i.e. ({g * p - p}, {g * p}]. Got: grid={g}, patch={p}. What it means
Error "For `padding='same'`, `output_size` {dim_name} ({o}) must be in the range ((g-1)*p, g*p], i.e. ({g * p - p}, {g * p}]. Got: grid={g}, patch={p}." thrown in keras-team/keras.
Source
Thrown at keras/src/ops/image.py:1030
else:
# channels_first: the grid dims are the trailing dims,
# (B, flat, *grid) batched or (flat, *grid) unbatched.
grid = patches_shape[-len(self.size) :]
dim_names = ("depth", "height", "width")[-len(self.size) :]
for g, p, o, dim_name in zip(
grid, self.size, self.output_size, dim_names
):
if not isinstance(g, int):
continue
if self.padding == "valid":
if g * p != o:
raise ValueError(
f"`padding='valid'` requires output_size to equal "
f"size * grid. Got output_size={self.output_size}, "
f"grid {dim_name}={g}, size={self.size}."
)
elif not (g * p - p < o <= g * p):
raise ValueError(
f"For `padding='same'`, `output_size` {dim_name} ({o}) "
f"must be in the range ((g-1)*p, g*p], i.e. "
f"({g * p - p}, {g * p}]. Got: grid={g}, patch={p}."
)
if self.data_format == "channels_last":
out_shape = list(spatial) + [channels_out]
else:
out_shape = [channels_out] + list(spatial)
if original_ndim == expected_ndim_batched:
out_shape = [batch] + out_shape
return KerasTensor(shape=tuple(out_shape), dtype=patches.dtype)
def get_config(self):
return {
"size": self.size,
"output_size": self.output_size,View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/ops/image.py:1030 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/8c5f0121c76f5c1f.
Report an issue: GitHub.