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
Fixing LocallyConnected2D and LocallyConnected1D layer Save Model to tf issue #49230
Fixing LocallyConnected2D and LocallyConnected1D layer Save Model to tf issue #49230
Conversation
Can you add a test to cover the mentioned tickets case? |
@ashutosh1919 |
@AdityaKane2001 , how are you running code in my branch? I see direct import |
@ashutosh1919 |
Updated gist here. I have used your code as mentioned above. Still facing the same error. |
@AdityaKane2001 , I have resolved the error and added test cases. And btw, I think you can't just change the code for @bhack , I have added the test case to save all 3 implementation of models and the problem is there for Solution (Attempt 2):Actually at the time of
Any other suggestions on this are welcome. Also I would suggest you to please review code and suggest changes because I have raised |
@ashutosh1919 Anyways, apart from that, everything looks good. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
It looks like the LocallyConnected layer is failing as you noted, the input shapes have None
in them. This is due to the input_spec being used as the inputs (for most Keras built-in layers using the input spec is fine, but not for LocallyConnected layers):
A simple fix would be overwriting this property to the LocallyConnected1D and LocallyConnected2D:
class LocallyConnected1D:
...
@property
def _use_input_spec_as_call_signature(self):
return False
@k-w-w , Thanks for straight forward and easy solution. I got to learn something new here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks !
Fixes #48584 and #47689 .
My understanding:
The model save is failing because at the time of saving,
call()
of LocallyConnected2D will be invoked which is not passed with any inputs (None). That is whycompute_output_shape
andlocal_conv_matmul
fails and thussave
fails.Solution that I propose:
We particularly don't require any input data at the time of saving. So, I am saving the input_shape at the time when LocallyConnected2D instance is
build()
and whenever the parameterinputs
isNone
incall()
, I am replacinginputs
with the dummy tensor with shapeinput_shape
which was saved inbuild()
.Any suggestions on optimisation of solution are welcomed.
cc @mihaimaruseac , @bhack , @ AdityaKane2001