-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Recurrent layer to treat 2nd and the rest of inputs as initial_states #7691
Merged
fchollet
merged 3 commits into
keras-team:master
from
wanasit:recurrent_inputs_as_init_states
Aug 24, 2017
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
from keras import backend as K | ||
from keras.models import Model, Sequential | ||
from keras.layers import Dense, Lambda, RepeatVector, TimeDistributed | ||
from keras.layers import Dense, Lambda, RepeatVector, TimeDistributed, LSTM | ||
from keras.layers import Input | ||
from keras import optimizers | ||
from keras import losses | ||
|
@@ -351,5 +351,24 @@ def test_saving_custom_activation_function(): | |
assert_allclose(out, out2, atol=1e-05) | ||
|
||
|
||
@keras_test | ||
def test_saving_recurrent_layer_with_init_state(): | ||
VECTOR_SIZE = 8 | ||
INPUT_LENGTH = 20 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for all caps variable names here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changing to lower case |
||
|
||
input_initial_state = Input(shape=(VECTOR_SIZE,)) | ||
input_x = Input(shape=(INPUT_LENGTH, VECTOR_SIZE)) | ||
|
||
lstm = LSTM(VECTOR_SIZE, return_sequences=True)( | ||
input_x, initial_state=[input_initial_state, input_initial_state]) | ||
|
||
model = Model(inputs=[input_x, input_initial_state], outputs=[lstm]) | ||
|
||
_, fname = tempfile.mkstemp('.h5') | ||
model.save(fname) | ||
|
||
loaded_model = load_model(fname) | ||
os.remove(fname) | ||
|
||
if __name__ == '__main__': | ||
pytest.main([__file__]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use
train_on_batch
to make the test lighter. Similarly I suggest you use2
instead ofnum_samples
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.
Switching to
train_on_batch
, butnum_samples
is already defined as 2 at the beginning of the file, isn't it.