keras-team/keras · error · ValueError
left_padding must be >= 0. Received: left_padding=
Error message
left_padding must be >= 0. Received: left_padding={left_padding} What it means
Raised by the ZeroPadding2D compute_output_shape logic: when the left padding is not explicitly configured it is inferred as target_width - width - right_padding, and a negative result means the configured width/padding combination is geometrically impossible (input plus paddings cannot reach the target).
Solutions
- Pass a non-negative left_padding
- Ensure target_width >= width + left_padding + right_padding
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/ops/image.py:1701 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/efdc35bec1367867.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/ops/image.py:1701
raise ValueError(
"bottom_padding must be >= 0. "
f"Received: bottom_padding={bottom_padding}"
)
if target_height < 0:
raise ValueError(
"target_height must be >= 0. "
f"Received: target_height={target_height}"
)
if width is not None:
left_padding = self.left_padding
right_padding = self.right_padding
if left_padding is None:
left_padding = target_width - width - right_padding
if right_padding is None:
right_padding = target_width - width - left_padding
if left_padding < 0:
raise ValueError(
"left_padding must be >= 0. "
f"Received: left_padding={left_padding}"
)
if right_padding < 0:
raise ValueError(
"right_padding must be >= 0. "
f"Received: right_padding={right_padding}"
)
if target_width < 0:
raise ValueError(
"target_width must be >= 0. "
f"Received: target_width={target_width}"
)
images_shape[height_axis] = target_height
images_shape[width_axis] = target_width
return KerasTensor(shape=images_shape, dtype=images.dtype)
View on GitHub (pinned to 7a34a03db6)