Guest User

Untitled

a guest
Jun 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. from keras.models import Model
  2. from keras.layers import Input
  3. from keras.layers import LSTM
  4. import numpy as np
  5.  
  6.  
  7. batch_size = 1
  8. timesteps = 1
  9. input_features_count = 1
  10. output_features_count = 1
  11. inputs1 = Input(batch_shape=(batch_size, timesteps, input_features_count))
  12. lstm1 = LSTM(units = output_features_count, return_sequences=True, return_state=True, stateful=True)(inputs1)
  13. model = Model(inputs=inputs1, outputs=lstm1)
  14. data = array([0.1]).reshape((batch_size, timesteps, input_features_count))
  15. pred_seq, state_h, state_c = model.predict(data)
  16. print(pred_seq.shape) # (1, 1, 1)
  17. print(state_h.shape) # (1, 1)
  18. print(state_c.shape) # (1, 1)
  19.  
  20.  
  21. batch_size = 1
  22. timesteps = 2
  23. input_features_count = 3
  24. output_features_count = 5
  25. inputs1 = Input(batch_shape=(batch_size, timesteps, input_features_count))
  26. lstm1 = LSTM(units = output_features_count, return_sequences=True, return_state=True, stateful=True)(inputs1)
  27. model = Model(inputs=inputs1, outputs=lstm1)
  28. data = array([1,2,3,4,5,6]).reshape((batch_size, timesteps, input_features_count))
  29. pred_seq, state_h, state_c = model.predict(data)
  30. print(pred_seq.shape) # (1, 2, 5)
  31. print(state_h.shape) # (1, 5)
  32. print(state_c.shape) # (1, 5)
Add Comment
Please, Sign In to add comment