0
votes

I build a keras functionnal model and when I plot the summary, the first conv1d layer don't appear...

from tensorflow.keras.layers import Input, Dense, LSTM, Dropout, TimeDistributed, Conv1D, 
     MaxPooling1D, Flatten
from tensorflow.keras import Model, regularizers, initializers

tensor_input = Input(shape=(Xn.shape[1], Xn.shape[2]), name='main_inputs')

xy = TimeDistributed(Conv1D(filters= 10, kernel_size= 3,
                            activation=params['activationCNN1']))
xy = TimeDistributed(MaxPooling1D(pool_size= 2))

xy = TimeDistributed(Conv1D(filters=5, kernel_size= 2,
                        activation=params['activationCNN1']), name='Cnn1d-2')
xy = TimeDistributed(MaxPooling1D(pool_size= 2), name='MaxPool')
xy = TimeDistributed(Flatten(), name='Flatten')

xy = LSTM(params['unitsLstm1'],activation=params['activationLSTM1'],
          return_sequences=False, stateful=params['stateful'], 
          name='Hlayer1')(tensor_input)
xy = Dropout(rate = params['dropout1'])(xy)

xy = Dense(params['unitsDense1'], activation=params['activationDense1'],
           kernel_initializer= initializers.he_uniform(), name='Dense1')(xy)
xy = Dropout(rate = params['dropout2'])(xy)

out = Dense(autres_param['timestepsOut'], activation=params['activationDenseOutput'],
            kernel_initializer= initializers.he_uniform(), name='DenseOutput')(xy) 
model = Model(inputs=tensor_input, outputs=out)

model.compile(optimizer=optimizer, loss=params['loss'])
# summarize layers
print(model.summary())

What I get is: only the input, lstm, dropout and dense layers...

summary output

The trainning seem to work but all layer are active? How can I get the full summary??

2
Ooh, I see the bug :) hint: TimeDistributed is also a layer and needs to be connected to the inputStefan Dragnev
ohhhh ... yeahhh total newbi error, sorry for this dumb question it is ambarrassing :(Jonathan Roy

2 Answers

0
votes

You need to call each layer on the previous ouput tensor:

tensor_input = Input(shape=(Xn.shape[1], Xn.shape[2]), name='main_inputs')

xy = TimeDistributed(Conv1D(filters= 10, kernel_size= 3,
                            activation=params['activationCNN1']))(tensor_input)
xy = TimeDistributed(MaxPooling1D(pool_size= 2))(xy)

xy = TimeDistributed(Conv1D(filters=5, kernel_size= 2,
                        activation=params['activationCNN1']), name='Cnn1d-2')(xy)
xy = TimeDistributed(MaxPooling1D(pool_size= 2), name='MaxPool')(xy)
xy = TimeDistributed(Flatten(), name='Flatten')(xy)

xy = LSTM(params['unitsLstm1'],activation=params['activationLSTM1'],
          return_sequences=False, stateful=params['stateful'], 
          name='Hlayer1')(xy)

In general, the summary is good at showing all part of the model. If something is not shown in the summary, it's safe to assume that that means that it's not in the model.

0
votes

In

xy = LSTM(params['unitsLstm1'],activation=params['activationLSTM1'],
          return_sequences=False, stateful=params['stateful'], 
          name='Hlayer1')(tensor_input)

you call the LSTM on tensor_input, so basically all this:

xy = TimeDistributed(Conv1D(filters= 10, kernel_size= 3,
                            activation=params['activationCNN1']))
xy = TimeDistributed(MaxPooling1D(pool_size= 2))

xy = TimeDistributed(Conv1D(filters=5, kernel_size= 2,
                        activation=params['activationCNN1']), name='Cnn1d-2')
xy = TimeDistributed(MaxPooling1D(pool_size= 2), name='MaxPool')
xy = TimeDistributed(Flatten(), name='Flatten')

is ignored.