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

Fixed bug related to KerasSymbol.tensor #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jricheimer
Copy link

This prevents the unfortunate scenario in which layer.set_weights() is called before training on some or all layers in a model, and then the model is trained and saved.

When the weights are set, since weight.tensor already exists from the random initialization, it is getting reassigned to a new symbol, whereas weight._bind_values[weight.name] remains pointing to the same symbol and only its values are being replaced by the new data. When model._sync_weights() is eventually called, the model._args[weight.name] and weight._bind_values[weight.name] contains the updated (trained) weights, but weight.tensor contains the old initialization values. And it is the weight.tensor which gets evaluated when calling model.save_weights() or layer.get_weights(). Therefore, incorrect weights are getting saved to the Keras model files.

Potentially, this is also the bug causing this issue.

The easy fix here is to keep the symbol which weight.tensor is pointing to and only replace it's values with new data, same as is done with weight._bind_values[weight.name].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant