# keras CNN lstm add model depth

Would anyone have any advice on how to add model depth? This works below but I was hoping to experiment with adding in additional non-TimeDistributed layers.

# reshape from [samples, timesteps] into [samples, subsequences, timesteps, features]
n_features = 1
n_seq = 2
n_steps = 2

# define model
model = Sequential()
model.add(TimeDistributed(Conv1D(filters=16, kernel_size=1, activation='relu'), input_shape=(None, n_steps, n_features)))
# fit model
model.fit(X, y, epochs=500, verbose=0)


For example, if I add this in:

# define model
model = Sequential()
model.add(TimeDistributed(Conv1D(filters=16, kernel_size=1, activation='relu'), input_shape=(None, n_steps, n_features)))
# fit model
model.fit(X, y, epochs=500, verbose=0)


This will throw ValueError: Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2

Any tips help! Sorry not a lot of Wisdom here but learning :)

CTry to change

model.add(LSTM(50, activation='relu'))


to

model.add(LSTM(50, activation='relu', return_sequences=True))


as explained in the documentation ( https://keras.io/layers/recurrent/#lstm ) return_sequences allow the LSTM to return the complete sequence of vectors of the LSTM rather than a single vector.

• Thanks this worked I needed to add this to all layers but the last one Mar 10 '20 at 18:14
• Any chance you could help me with this too? stackoverflow.com/questions/60568604/… Mar 10 '20 at 18:15