Skip to content

Commit

Permalink
Validate cropping arg value for -ve ints (#18965)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuryanarayanaY authored Dec 19, 2023
1 parent c3d269b commit 1965969
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions keras/layers/reshaping/cropping2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions keras/layers/reshaping/cropping3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 1965969

Please sign in to comment.