diff --git a/keras/layers/reshaping/cropping2d.py b/keras/layers/reshaping/cropping2d.py index 05bb82bc4c8..867ea0512bf 100644 --- a/keras/layers/reshaping/cropping2d.py +++ b/keras/layers/reshaping/cropping2d.py @@ -57,6 +57,11 @@ def __init__(self, cropping=((0, 0), (0, 0)), 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)) elif hasattr(cropping, "__len__"): if len(cropping) != 2: diff --git a/keras/layers/reshaping/cropping3d.py b/keras/layers/reshaping/cropping3d.py index ee55e886c02..7c415595ca9 100644 --- a/keras/layers/reshaping/cropping3d.py +++ b/keras/layers/reshaping/cropping3d.py @@ -62,6 +62,11 @@ def __init__( 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),