Skip to content

Commit

Permalink
Correct the Error description in cropping layer APIs (#18974)
Browse files Browse the repository at this point in the history
* Correct the Error description in cropping APIs

* Fix failing cropping test cases
  • Loading branch information
SuryanarayanaY authored Dec 21, 2023
1 parent e51ecdd commit fe2f54a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions keras/layers/reshaping/cropping1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def compute_output_shape(self, input_shape):
if length <= 0:
raise ValueError(
"`cropping` parameter of `Cropping1D` layer must be "
"greater than the input length. Received: input_shape="
"smaller than the input length. Received: input_shape="
f"{input_shape}, cropping={self.cropping}"
)
else:
Expand All @@ -68,7 +68,7 @@ def call(self, inputs):
):
raise ValueError(
"`cropping` parameter of `Cropping1D` layer must be "
"greater than the input length. Received: inputs.shape="
"smaller than the input length. Received: inputs.shape="
f"{inputs.shape}, cropping={self.cropping}"
)
if self.cropping[1] == 0:
Expand Down
4 changes: 2 additions & 2 deletions keras/layers/reshaping/cropping1d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_cropping_1d_errors_if_cropping_argument_invalid(self):
def test_cropping_1d_errors_if_cropping_more_than_available(self):
with self.assertRaisesRegex(
ValueError,
"`cropping` parameter of `Cropping1D` layer must be greater than",
"`cropping` parameter of `Cropping1D` layer must be smaller than",
):
input_layer = layers.Input(batch_shape=(3, 5, 7))
layers.Cropping1D(cropping=(2, 3))(input_layer)
Expand All @@ -74,7 +74,7 @@ def test_cropping_1d_error_on_excessive_cropping(self):

with self.assertRaisesRegex(
ValueError,
"`cropping` parameter of `Cropping1D` layer must be greater than",
"`cropping` parameter of `Cropping1D` layer must be smaller than",
):
layer = layers.Cropping1D(cropping=(3, 3))
_ = layer(inputs)
8 changes: 4 additions & 4 deletions keras/layers/reshaping/cropping2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def compute_output_shape(self, input_shape):
and sum(self.cropping[1]) >= input_shape[3]
):
raise ValueError(
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input. Received: "
f"input_shape={input_shape}, cropping={self.cropping}"
)
Expand All @@ -119,7 +119,7 @@ def compute_output_shape(self, input_shape):
and sum(self.cropping[1]) >= input_shape[2]
):
raise ValueError(
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input. Received: "
f"input_shape={input_shape}, cropping={self.cropping}"
)
Expand All @@ -144,7 +144,7 @@ def call(self, inputs):
and sum(self.cropping[1]) >= inputs.shape[3]
):
raise ValueError(
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input. Received: "
f"inputs.shape={inputs.shape}, cropping={self.cropping}"
)
Expand Down Expand Up @@ -181,7 +181,7 @@ def call(self, inputs):
and sum(self.cropping[1]) >= inputs.shape[2]
):
raise ValueError(
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input. Received: "
f"inputs.shape={inputs.shape}, cropping={self.cropping}"
)
Expand Down
2 changes: 1 addition & 1 deletion keras/layers/reshaping/cropping2d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_cropping_2d_error_on_excessive_cropping(

with self.assertRaisesRegex(
ValueError,
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input.",
):
layer = layers.Cropping2D(
Expand Down
4 changes: 2 additions & 2 deletions keras/layers/reshaping/cropping3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def compute_output_shape(self, input_shape):
spatial_dims[index] -= sum(self.cropping[index])
if spatial_dims[index] <= 0:
raise ValueError(
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input. Received: "
f"input_shape={input_shape}, cropping={self.cropping}"
)
Expand All @@ -134,7 +134,7 @@ def call(self, inputs):
spatial_dims[index] -= sum(self.cropping[index])
if spatial_dims[index] <= 0:
raise ValueError(
"Values in `cropping` argument should be greater than the "
"Values in `cropping` argument should be smaller than the "
"corresponding spatial dimension of the input. Received: "
f"inputs.shape={inputs.shape}, cropping={self.cropping}"
)
Expand Down
2 changes: 1 addition & 1 deletion keras/layers/reshaping/cropping3d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_cropping_3d_with_excessive_cropping(self, cropping, data_format):
input_layer = layers.Input(batch_shape=shape)

expected_error_msg = (
"Values in `cropping` argument should be greater than the"
"Values in `cropping` argument should be smaller than the"
)

with self.assertRaisesRegex(ValueError, expected_error_msg):
Expand Down

0 comments on commit fe2f54a

Please sign in to comment.