maxpooling2d keras does not do pooling at all

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



maxpooling2d keras does not do pooling at all



I am writing a CNN for text classification. The max pooling2D layer seems does not work as the output shape is same as conv2D. I have attached my code and output shape below. Thanks for helping me!


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'])



output shape for each layer









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS