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: input_shape={input_shape}, cropping={self.cropping}

What it means

Raised by Cropping1D.compute_output_shape: after subtracting the left and right crop amounts from the temporal axis (input_shape[1]) the remaining length is <= 0, meaning the cropping would remove the entire axis (or more). The layer cannot produce an empty output tensor.

Solutions

  1. Reduce the cropping values so that cropping[0] + cropping[1] < input length
  2. Use asymmetric cropping like Cropping1D(cropping=(1, 0)) to fit within the available length
  3. Verify the actual input length before choosing crop sizes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/layers/reshaping/cropping1d.py:55 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/964a21b5c7b6d5ea. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/reshaping/cropping1d.py:55

    Input shape:
        3D tensor with shape `(batch_size, axis_to_crop, features)`

    Output shape:
        3D tensor with shape `(batch_size, cropped_axis, features)`
    """

    def __init__(self, cropping=(1, 1), **kwargs):
        super().__init__(**kwargs)
        self.cropping = argument_validation.standardize_tuple(
            cropping, 2, "cropping", allow_zero=True
        )
        self.input_spec = InputSpec(ndim=3)

    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}"
            )

View on GitHub (pinned to 7a34a03db6)