keras-team/keras · error · ValueError
`cropping` parameter of `Cropping1D` layer must be smaller…
Error message
`cropping` parameter of `Cropping1D` layer must be smaller than the input length. Received: inputs.shape={inputs.shape}, cropping={self.cropping} What it means
Raised by Cropping1D.call at execution time: the sum of the two crop amounts is >= the temporal dimension of the actual input tensor (inputs.shape), so the cropped axis would be empty or negative. This is the runtime counterpart of the compute_output_shape check and fires when shapes were unknown at build time.
Solutions
- Lower the cropping so the sum of both ends is smaller than the sequence length of the data actually fed to the layer
- Check that the input tensor really has the temporal size you assume (e.g. after an upstream layer changed it)
- Use dynamic shapes carefully: validate crop sizes against runtime sequence length
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/reshaping/cropping1d.py:69 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/0adfa0e9b51ceb32.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/reshaping/cropping1d.py:69
def compute_output_shape(self, input_shape):
if input_shape[1] is not None:
length = input_shape[1] - self.cropping[0] - self.cropping[1]
if length <= 0:
raise ValueError(
"`cropping` parameter of `Cropping1D` layer must be "
"smaller than the input length. Received: input_shape="
f"{input_shape}, cropping={self.cropping}"
)
else:
length = None
return (input_shape[0], length, input_shape[2])
def call(self, inputs):
if (
inputs.shape[1] is not None
and sum(self.cropping) >= inputs.shape[1]
):
raise ValueError(
"`cropping` parameter of `Cropping1D` layer must be "
"smaller than the input length. Received: inputs.shape="
f"{inputs.shape}, cropping={self.cropping}"
)
if self.cropping[1] == 0:
return inputs[:, self.cropping[0] :, :]
else:
return inputs[:, self.cropping[0] : -self.cropping[1], :]
def get_config(self):
config = {"cropping": self.cropping}
base_config = super().get_config()
return {**base_config, **config}
View on GitHub (pinned to 7a34a03db6)