# Convert Lasagne to Keras code (CNN -> LSTM)

I would like to convert this Lasagne code:

et = {}
net['input'] = lasagne.layers.InputLayer((100, 1, 24, 113))
net['conv1/5x1'] = lasagne.layers.Conv2DLayer(net['input'], 64, (5, 1))
net['shuff'] = lasagne.layers.DimshuffleLayer(net['conv1/5x1'], (0, 2, 1, 3))
net['lstm1'] = lasagne.layers.LSTMLayer(net['shuff'], 128)


in Keras code. Currently I came up with this:

multi_input = Input(shape=(1, 24, 113), name='multi_input')
y = Conv2D(64, (5, 1), activation='relu', data_format='channels_first')(multi_input)
y = LSTM(128)(y)


But I get the error: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4

I know the difficult part is to connect an LSTM to the output of Conv2D. Maybe using TimeDistributed?

• The output of my conv2D is (filters, timestamps, features) so I did y = Reshape((filters*timestamps,features))(conv_outpu). Do you think is right? And why Lasagne is different and doesn't need a reshape? – Francesco Pegoraro Nov 5 '18 at 16:52