我建立了一个keras功能模型,当我绘制摘要时,第一个conv1d层没有出现...
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())
我得到的是:仅输入,lstm,辍学和密集层...
培训似乎有效,但是所有层都处于活动状态?我如何获得完整的摘要?
答案 0 :(得分:0)
您需要调用前一个输出张量上的每一层:
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)
通常,摘要擅长显示模型的所有部分。如果摘要中未显示某些内容,则可以安全地假定这表示它不在模型中。
答案 1 :(得分:0)
在
xy = LSTM(params['unitsLstm1'],activation=params['activationLSTM1'],
return_sequences=False, stateful=params['stateful'],
name='Hlayer1')(tensor_input)
您在LSTM
上呼叫tensor_input
,因此基本上所有这一切:
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')
被忽略。