keras-team/keras · error · ValueError
Must specify exactly two of left_cropping, right_cropping, t
Error message
Must specify exactly two of left_cropping, right_cropping, target_width. Received: left_cropping={left_cropping}, right_cropping={right_cropping}, target_width={target_width} What it means
Width triple rule for crop_images: exactly two of left_cropping, right_cropping, target_width must be given; anything else raises at output-spec/validation time.
Source
Thrown at keras/src/ops/image.py:1589
def _validate_crop_images_args(
top_cropping,
left_cropping,
bottom_cropping,
right_cropping,
target_height,
target_width,
):
if [top_cropping, bottom_cropping, target_height].count(None) != 1:
raise ValueError(
"Must specify exactly two of "
"top_cropping, bottom_cropping, target_height. "
f"Received: top_cropping={top_cropping}, "
f"bottom_cropping={bottom_cropping}, "
f"target_height={target_height}"
)
if [left_cropping, right_cropping, target_width].count(None) != 1:
raise ValueError(
"Must specify exactly two of "
"left_cropping, right_cropping, target_width. "
f"Received: left_cropping={left_cropping}, "
f"right_cropping={right_cropping}, "
f"target_width={target_width}"
)
_validate_non_negative(top_cropping, "top_cropping")
_validate_non_negative(bottom_cropping, "bottom_cropping")
_validate_non_negative(target_height, "target_height")
_validate_non_negative(left_cropping, "left_cropping")
_validate_non_negative(right_cropping, "right_cropping")
_validate_non_negative(target_width, "target_width")
class PadImages(Operation):
def __init__(
self,View on GitHub (pinned to 7a34a03db6)
Solutions
- Provide exactly two, e.g. target_width=224, left_cropping=0
- Symmetric: left_cropping=c, right_cropping=c
- Validate width independently of height
Example fix
# before out = crop_images(img, target_height=224, top_cropping=0) # width underdetermined # after out = crop_images(img, target_height=224, top_cropping=0, target_width=224, left_cropping=0)
Defensive patterns
Strategy: validation
Validate before calling
assert [left_cropping, right_cropping, target_width].count(None) == 1
Type guard
def crop_width_triple_ok(l, r, tw) -> bool:
return [l, r, tw].count(None) == 1 Prevention
- Validate both crop axes together
- Watch for typos in kwargs silently yielding None
When it happens
Trigger: crop_images with width args specified 0, 1, or 3 times, e.g. only target_width=224.
Common situations: Same shape as the height variant: partial configs, typo'd keys, mixing pad/crop kwargs.
Related errors
- Must specify exactly two of top_cropping, bottom_cropping, t
- Expected `size` to be a tuple of 2 integers. Received: size=
- `size` must have positive height and width. Received: size={
- Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` c
- {name} must be >= 0. Received: {name}={value}
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/1db66f95c43c22eb.
Report an issue: GitHub.