在Keras中,通常会写:
model = Sequential()
model.add(LSTM(n, input_shape=(ntimesteps, nfeatures),
return_sequences=return_sequences, return_state=return_state))
如何在纯Tensorflow 2中模拟return_sequences
和return_state
功能?
Keras是TensorFlow 2的高级API,所以你也可以这样做,唯一的区别是不再导入Keras,而是导入
import tensorflow as tf
print(tf.__version__) # 2.x
model = tf.keras.Sequential()
model.add(tf.keras.layers.LSTM(n, input_shape=(ntimesteps, nfeatures),
return_sequences=return_sequences, return_state=return_state))