lstm官方demo,有好几种输出的shape
import tensorflow as tf inputs = tf.random.normal([32, 10, 8]) lstm = tf.keras.layers.LSTM(4) output = lstm(inputs) print(output.shape) lstm = tf.keras.layers.LSTM(4, return_sequences=True, return_state=True) whole_seq_output, final_memory_state, final_carry_state = lstm(inputs) print(whole_seq_output.shape) print(final_memory_state.shape) print(final_carry_state.shape)
(32, 4) (32, 10, 4) (32, 4) (32, 4)