Cómo apilar múltiples lstm en keras?


Estoy usando la biblioteca de aprendizaje profundo keras e intentando apilar múltiples LSTM sin suerte. A continuación se muestra mi código

model = Sequential()
model.add(LSTM(100,input_shape =(time_steps,vector_size)))
model.add(LSTM(100))

El código anterior devuelve un error en la tercera línea Exception: Input 0 is incompatible with layer lstm_28: expected ndim=3, found ndim=2

La entrada X es un tensor de forma (100,250,50). Estoy ejecutando keras en tensorflow backend

Author: Tamim Addari, 2016-10-30

1 answers

Debe agregar return_sequences=True a la primera capa para que su tensor de salida tenga ndim=3 (es decir, tamaño del lote, pasos de tiempo, estado oculto).

Por favor vea el siguiente ejemplo:

# expected input data shape: (batch_size, timesteps, data_dim)
model = Sequential()
model.add(LSTM(32, return_sequences=True,
               input_shape=(timesteps, data_dim)))  # returns a sequence of vectors of dimension 32
model.add(LSTM(32, return_sequences=True))  # returns a sequence of vectors of dimension 32
model.add(LSTM(32))  # return a single vector of dimension 32
model.add(Dense(10, activation='softmax'))

De: https://keras.io/getting-started/sequential-model-guide / (buscar"stacked lstm")

 45
Author: Daniel Adiwardana,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-06 17:20:46