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

Lambda.compute_output_shape generates wrong shape #19324

Closed
AGFACBNNR opened this issue Mar 18, 2024 · 4 comments
Closed

Lambda.compute_output_shape generates wrong shape #19324

AGFACBNNR opened this issue Mar 18, 2024 · 4 comments
Assignees
Labels
keras-team-review-pending Pending review by a Keras team member. type:Bug

Comments

@AGFACBNNR
Copy link

When I use compute_output_shape() to help with shape inferencing, I found the Lambda layer may generate a wrong shape.
The code reproducing it:

from keras.layers import Lambda
import numpy as np
L=Lambda(lambda x:x**2, output_shape=[6])
x=np.zeros((3,2))
print(L(x).shape)
print(L.compute_output_shape(x.shape))

The results would be:
(3, 2)
(3, 6)

@AGFACBNNR AGFACBNNR changed the title Lambda.compute_output_shape generate wrong shape Lambda.compute_output_shape generates wrong shape Mar 18, 2024
@SuryanarayanaY
Copy link
Contributor

Hi @AGFACBNNR ,

Thanks for reporting. It seems users can set output_shape to any value without validating. I tested a demo where a simple model fails in inference when set random output_shape to it. But without setting output_shape it infers from the inputs and inference works fine. Attached gist for same.

I am not actually getting the intent/use case of output_shape here. If users sets output_shape explicitly in a model it will raise an exception if not compatible with the inputs provided. Will escalate to dev team and let's hear from them. Thanks!

@SuryanarayanaY SuryanarayanaY added the keras-team-review-pending Pending review by a Keras team member. label Mar 18, 2024
@nkovela1
Copy link
Contributor

Hi @AGFACBNNR , since the output_shape was specified to 6, compute_output_shape will return that corresponding shape (3,6). Please try removing the output_shape argument from the Lambda layer. Thanks!

@sampathweb
Copy link
Collaborator

Hope this addresses this issue. If you still think its open, please re-open it.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keras-team-review-pending Pending review by a Keras team member. type:Bug
Projects
None yet
Development

No branches or pull requests

4 participants