keras-team/keras · error · ValueError

`cropping` cannot be negative. Received: cropping={cropping}

Error message

`cropping` cannot be negative. Received: cropping={cropping}.

What it means

Error "`cropping` cannot be negative. Received: cropping={cropping}." thrown in keras-team/keras.

Source

Thrown at keras/src/layers/reshaping/cropping3d.py:66

    Output shape:
        5D tensor with shape:
        - If `data_format` is `"channels_last"`:
          `(batch_size, first_cropped_axis, second_cropped_axis,
          third_cropped_axis, channels)`
        - If `data_format` is `"channels_first"`:
          `(batch_size, channels, first_cropped_axis, second_cropped_axis,
          third_cropped_axis)`
    """

    def __init__(
        self, cropping=((1, 1), (1, 1), (1, 1)), data_format=None, **kwargs
    ):
        super().__init__(**kwargs)
        self.data_format = backend.standardize_data_format(data_format)
        if isinstance(cropping, int):
            if cropping < 0:
                raise ValueError(
                    "`cropping` cannot be negative. "
                    f"Received: cropping={cropping}."
                )
            self.cropping = (
                (cropping, cropping),
                (cropping, cropping),
                (cropping, cropping),
            )
        elif hasattr(cropping, "__len__"):
            if len(cropping) != 3:
                raise ValueError(
                    f"`cropping` should have 3 elements. Received: {cropping}."
                )
            dim1_cropping = argument_validation.standardize_tuple(
                cropping[0], 2, "1st entry of cropping", allow_zero=True
            )
            dim2_cropping = argument_validation.standardize_tuple(
                cropping[1], 2, "2nd entry of cropping", allow_zero=True

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/reshaping/cropping3d.py:66 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/48b889976465c976. Report an issue: GitHub.