我已经建立了这个简单的LSTM模型,它提供了与我的输入相同的3维输出。但是我的目标数据是2维的。有没有办法在特定的访问中平均输出。
batch_sizes = 1
epochs = 2
timesteps = 20
inputs_1_mae = tf.keras.layers.Input(shape = (20,10),batch_size = batch_sizes)
lstm_1_mae = tf.keras.layers.LSTM(10, stateful = True, return_sequences = True)(inputs_1_mae)
lstm_2_mae = tf.keras.layers.LSTM(10, stateful = True, return_sequences = True)(lstm_1_mae)
output_1_mae = tf.keras.layers.Dense(units = 10)(lstm_2_mae)
regressor_mae = tf.keras.Model(inputs= inputs_1_mae ,outputs = output_1_mae)
regressor_mae.compile (optimizer = "adam", loss = "mae")
regressor_mae.summary()
regressor_mae.fit(final_x_array, final_y_array, batch_size = batch_sizes, epochs=epochs)
下面是模型的总结:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_16 (InputLayer) [(1, 20, 10)] 0
lstm_17 (LSTM) (1, 20, 10) 840
lstm_18 (LSTM) (1, 20, 10) 840
dense_16 (Dense) (1, 20, 10) 110
我希望输出的形状是(1,10)。我如何消除那个特定的轴?谢谢
2条答案
按热度按时间p4rjhz4m1#
只需remove return_sequences = True of your last lstm layer,因为您只需要最后的输出。
tf7tbtn22#
您可以使用Lambda层来实现这一点。以下内容可能会有所帮助:
输出: