Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the dynamic has a result, but the static inference shape reports an error #20242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions keras/src/ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,9 @@ def average_pool(
data_format = standardize_data_format(data_format)
padding = padding.lower()
if any_symbolic_tensors((inputs,)):
return AveragePool(
pool_size,
strides,
padding,
data_format,
).symbolic_call(inputs)
return operation_utils.compute_pooling_output_shape(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, the symbolic call should return a KerasTensor instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fchollet - Thanks for update. Let me have a resolve it and commit again.

inputs.shape, pool_size, strides, padding, data_format
)
return backend.nn.average_pool(
inputs, pool_size, strides, padding, data_format
)
Expand Down
20 changes: 10 additions & 10 deletions keras/src/ops/nn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ def test_average_pool(self):
input_shape = (None, 3, 8)
x = KerasTensor(input_shape)
self.assertEqual(
knn.average_pool(x, 2, 1).shape,
knn.average_pool(x, 2, 1),
(None, 7, 3) if data_format == "channels_last" else (None, 3, 7),
)
self.assertEqual(
knn.average_pool(x, 2, 2, padding="same").shape,
knn.average_pool(x, 2, 2, padding="same"),
(None, 4, 3) if data_format == "channels_last" else (None, 3, 4),
)

Expand All @@ -181,23 +181,23 @@ def test_average_pool(self):
input_shape = (None, 3, 8, None)
x = KerasTensor(input_shape)
self.assertEqual(
knn.average_pool(x, 2, 1).shape,
knn.average_pool(x, 2, 1),
(
(None, 7, None, 3)
if data_format == "channels_last"
else (None, 3, 7, None)
),
)
self.assertEqual(
knn.average_pool(x, 2, 2, padding="same").shape,
knn.average_pool(x, 2, 2, padding="same"),
(
(None, 4, None, 3)
if data_format == "channels_last"
else (None, 3, 4, None)
),
)
self.assertEqual(
knn.average_pool(x, (2, 2), (2, 2), padding="same").shape,
knn.average_pool(x, (2, 2), (2, 2), padding="same"),
(
(None, 4, None, 3)
if data_format == "channels_last"
Expand Down Expand Up @@ -780,11 +780,11 @@ def test_average_pool(self):
input_shape = (1, 3, 8)
x = KerasTensor(input_shape)
self.assertEqual(
knn.average_pool(x, 2, 1).shape,
knn.average_pool(x, 2, 1),
(1, 7, 3) if data_format == "channels_last" else (1, 3, 7),
)
self.assertEqual(
knn.average_pool(x, 2, 2, padding="same").shape,
knn.average_pool(x, 2, 2, padding="same"),
(1, 4, 3) if data_format == "channels_last" else (1, 3, 4),
)

Expand All @@ -794,15 +794,15 @@ def test_average_pool(self):
input_shape = (1, 3, 8, 8)
x = KerasTensor(input_shape)
self.assertEqual(
knn.average_pool(x, 2, 1).shape,
knn.average_pool(x, 2, 1),
(1, 7, 7, 3) if data_format == "channels_last" else (1, 3, 7, 7),
)
self.assertEqual(
knn.average_pool(x, 2, 2, padding="same").shape,
knn.average_pool(x, 2, 2, padding="same"),
(1, 4, 4, 3) if data_format == "channels_last" else (1, 3, 4, 4),
)
self.assertEqual(
knn.average_pool(x, (2, 2), (2, 2), padding="same").shape,
knn.average_pool(x, (2, 2), (2, 2), padding="same"),
(1, 4, 4, 3) if data_format == "channels_last" else (1, 3, 4, 4),
)

Expand Down