Я пишу CNN для классификации текста. Слой max pooling2D, кажется, не работает, поскольку форма вывода такая же, как и в conv2D. Я приложил свой код и форму вывода ниже. Спасибо за помощь!
from keras.layers import Dense, Input, Flatten
from keras.layers import Conv2D, MaxPooling2D, Embedding, Reshape, Concatenate, Dropout
from keras import optimizers
from keras.models import Model
convs = []
filter_sizes = [2,4,8]
BATCH_SIZE = 10
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
reshape = Reshape((MAX_SEQUENCE_LENGTH, EMBEDDING_DIM,1))(embedded_sequences)
conv_0 = Conv2D(filters = 128, kernel_size=(MAX_SEQUENCE_LENGTH, filter_sizes[0]), activation='relu')(reshape)
conv_1 = Conv2D(filters = 128, kernel_size=(MAX_SEQUENCE_LENGTH, filter_sizes[1]), activation='relu')(reshape)
conv_2 = Conv2D(filters = 128, kernel_size=(MAX_SEQUENCE_LENGTH, filter_sizes[2]), activation='relu')(reshape)
maxpool_0 = MaxPooling2D(pool_size=(MAX_SEQUENCE_LENGTH - filter_sizes[0] + 1,1), strides=(1,1), padding='same')(conv_0)
maxpool_1 = MaxPooling2D(pool_size=(MAX_SEQUENCE_LENGTH - filter_sizes[1] + 1, 1), strides=(1,1), padding='same')(conv_1)
maxpool_2 = MaxPooling2D(pool_size=(MAX_SEQUENCE_LENGTH - filter_sizes[2] + 1, 1), strides=(1,1), padding='same')(conv_2)
concatenated_tensor = Concatenate(axis = 2)([maxpool_0, maxpool_1, maxpool_2])
flatten = Flatten()(concatenated_tensor)
dense = Dense(2048, activation='relu')(flatten)
dense_out = Dropout(0.5)(dense)
preds = Dense(label_dim, activation='sigmoid')(dense_out)
model = Model(sequence_input, preds)
opt = optimizers.Adam(lr=0.0001)
model.compile(loss='binary_crossentropy',
optimizer=opt,
metrics=['acc'])
форма вывода для каждого слоя