Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.models import Model
- from keras.layers import Input
- from keras.layers import LSTM
- import numpy as np
- batch_size = 1
- timesteps = 1
- input_features_count = 1
- output_features_count = 1
- inputs1 = Input(batch_shape=(batch_size, timesteps, input_features_count))
- lstm1 = LSTM(units = output_features_count, return_sequences=True, return_state=True, stateful=True)(inputs1)
- model = Model(inputs=inputs1, outputs=lstm1)
- data = array([0.1]).reshape((batch_size, timesteps, input_features_count))
- pred_seq, state_h, state_c = model.predict(data)
- print(pred_seq.shape) # (1, 1, 1)
- print(state_h.shape) # (1, 1)
- print(state_c.shape) # (1, 1)
- batch_size = 1
- timesteps = 2
- input_features_count = 3
- output_features_count = 5
- inputs1 = Input(batch_shape=(batch_size, timesteps, input_features_count))
- lstm1 = LSTM(units = output_features_count, return_sequences=True, return_state=True, stateful=True)(inputs1)
- model = Model(inputs=inputs1, outputs=lstm1)
- data = array([1,2,3,4,5,6]).reshape((batch_size, timesteps, input_features_count))
- pred_seq, state_h, state_c = model.predict(data)
- print(pred_seq.shape) # (1, 2, 5)
- print(state_h.shape) # (1, 5)
- print(state_c.shape) # (1, 5)
Add Comment
Please, Sign In to add comment