我正在使用Keras构建CNN-LSTM模型以进行鸣叫分类。该模型有两个输入,任务是三类分类。我用于构建模型的代码如下:
def conv2d_lstm_with_author():
# Get the input information - author & tweet
author_repre_input = Input(shape=(100,), name='author_input')
tweet_input = Input(shape=(13, 100, 1), name='tweet_input')
# Create the convolutional layer and lstm layer
conv2d = Conv2D(filters = 200, kernel_size = (2, 100), padding='same', activation='relu',
use_bias=True, name='conv_1')(tweet_input)
flat = Flatten(name='flatten_1')(conv2d)
reshape_flat = Reshape((260000, 1), name='reshape_1')(flat)
lstm = LSTM(100, return_state=False, activation='tanh', recurrent_activation='hard_sigmoid', name='lstm_1')(reshape_flat)
concatenate_layer = concatenate([lstm, author_repre_input], axis=1, name='concat_1')
dense_1 = Dense(10, activation='relu', name='dense_1')(concatenate_layer)
output = Dense(3, activation='softmax', kernel_regularizer=regularizers.l2(0.01), name='output_dense')(dense_1)
# Build the model
model = Model(inputs=[author_repre_input, tweet_input], outputs=output)
return model
model = conv2d_lstm_with_author()
model.summary()
optimizer = Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])
我的两个输入和标签的形状是:
author_repre_input: (40942, 100)
tweet_input: (40942, 13, 100, 1)
my label Train_Y: (40942, 3)
模型摘要的快照为:
当我使用以下代码训练数据时:
model.fit([author_repre_input, tweet_input], [Train_Y], epochs=20, batch_size=32, validation_split=0.2,
shuffle=False, verbose=2)
结果一直停留在第一个时期,并且日志中没有显示任何有用的信息,只是:
Epoch 1/20
我想知道为什么会这样。我正在使用的tensorflow和keras版本是:
tensorflow - 1.14.0
keras - 2.2.0
非常感谢您的光临!
1月20日更新...
我尝试使用Google Colab训练模型。我在运行模型时检查RAM。 Colab为我分配了25G RAM。但是,经过几秒钟的训练,由于占用了所有可用的RAM,会话崩溃了。
我认为模型部分一定有问题...任何建议和见解将不胜感激!
答案 0 :(得分:4)
幸运的是,您没有被困住。
问题出在以下事实:您在model.fit
中指定了参数verbose=2
。
这意味着您的代码只会在一个纪元末输出消息,而不会在训练过程中输出信息量丰富的消息。
要解决您的问题并查看培训进度,请设置verbose=1
。
答案 1 :(得分:0)