keras-team/keras · error · ValueError
`cropping` should be either an int, a tuple of 2 ints…
Error message
`cropping` should be either an int, a tuple of 2 ints (symmetric_height_crop, symmetric_width_crop), or a tuple of 2 tuples of 2 ints ((top_crop, bottom_crop), (left_crop, right_crop)). Received: cropping={cropping}. What it means
Error "`cropping` should be either an int, a tuple of 2 ints (symmetric_height_crop, symmetric_width_crop), or a tuple of 2 tuples of 2 ints ((top_crop, bottom_crop), (left_crop, right_crop)). Received: cropping={cropping}." thrown in keras-team/keras.
Solutions
- Pass an int (symmetric on both axes), a tuple of 2 ints ((sym_height_crop, sym_width_crop)), or a tuple of 2 tuples ((top, bottom), (left, right))
- Examples: Cropping2D(cropping=2), Cropping2D(cropping=(2, 3)), Cropping2D(cropping=((1, 2), (3, 4)))
- Check for accidentally nested or flattened sequences with the wrong depth
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/reshaping/cropping2d.py:80 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/b5e6b84f298ed8a9.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/reshaping/cropping2d.py:80
"`cropping` cannot be negative. "
f"Received: cropping={cropping}."
)
self.cropping = ((cropping, cropping), (cropping, cropping))
elif hasattr(cropping, "__len__"):
if len(cropping) != 2:
raise ValueError(
"`cropping` should have two elements. "
f"Received: cropping={cropping}."
)
height_cropping = argument_validation.standardize_tuple(
cropping[0], 2, "1st entry of cropping", allow_zero=True
)
width_cropping = argument_validation.standardize_tuple(
cropping[1], 2, "2nd entry of cropping", allow_zero=True
)
self.cropping = (height_cropping, width_cropping)
else:
raise ValueError(
"`cropping` should be either an int, a tuple of 2 ints "
"(symmetric_height_crop, symmetric_width_crop), "
"or a tuple of 2 tuples of 2 ints "
"((top_crop, bottom_crop), (left_crop, right_crop)). "
f"Received: cropping={cropping}."
)
self.input_spec = InputSpec(ndim=4)
def compute_output_shape(self, input_shape):
if self.data_format == "channels_first":
if (
input_shape[2] is not None
and sum(self.cropping[0]) >= input_shape[2]
) or (
input_shape[3] is not None
and sum(self.cropping[1]) >= input_shape[3]
):
raise ValueError(View on GitHub (pinned to 7a34a03db6)