keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.61k stars 19.42k forks source link

Merge layer with lambda - potential issue with reloading model after save #5167

Closed gtuzi closed 7 years ago

gtuzi commented 7 years ago

Hi, I have a model which uses a Merge() layer. The model runs and saves. I am having trouble loading the model again.

merged_layer = Merge(group_out, mode=lambda x: weighted_merge_fun(x, (num_experts, num_classes)),output_shape=(num_classes,))

The error I get is:

arg 5 (closure) must be None or tuple

After researching some previous issues, I saw that other people had potentially similar issues using the Lambda(). But I didn't get whether there was a solution to this.

I am running into this issue with both Python 2.7/3.5

Update:

I changed the merge layer. Lambda now takes only one argument, and the output shape is literally defined:

merged_layer = Merge(group_out, mode=lambda x: weighted_merge_fun(x), output_shape=(7,)) where group_out is a list of output layers from models being merged.

Now, when I try to load the model, the error is:

The layer has never been called and thus it has no defined output shape

Any help would be appreciated.

Gerti

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Thank you!

mobeets commented 7 years ago

This seems to be the same problem as #5396.

To reproduce this bug, just try to save the model in the variational autoencoder example here.

This definitely has to do with Lambdas, because if you change line 40 to say "z_mean" instead of "z", this problem goes away.

stale[bot] commented 7 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.