keras-team/keras · error · ValueError
target_height must be >= 0. Received: target_height=
Error message
target_height must be >= 0. Received: target_height={target_height} What it means
The cropping validation helper (used by pad/crop image ops) checks the computed/implied padding amounts; a negative target_height would mean padding more than the target allows, so it is rejected. Provide a non-negative target_height.
Solutions
- Pass a positive target_height
- Ensure target_height >= height plus the top/bottom paddings
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/ops/image.py:1688 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/260f48554b7030d7.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/ops/image.py:1688
if height is not None:
top_padding = self.top_padding
bottom_padding = self.bottom_padding
if top_padding is None:
top_padding = target_height - height - bottom_padding
if bottom_padding is None:
bottom_padding = target_height - height - top_padding
if top_padding < 0:
raise ValueError(
"top_padding must be >= 0. "
f"Received: top_padding={top_padding}"
)
if bottom_padding < 0:
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(View on GitHub (pinned to 7a34a03db6)