GlobalMaxPool1D和GlobalMaxPooling1D有什么区别?

时间:2019-06-13 21:57:53

标签: keras

在本教程here中,作者这样使用GlobalMaxPool1D()

from keras.models import Sequential
from keras.layers import Dense, Activation, Embedding, Flatten, GlobalMaxPool1D, Dropout, Conv1D
from keras.callbacks import ReduceLROnPlateau, EarlyStopping, ModelCheckpoint
from keras.losses import binary_crossentropy
from keras.optimizers import Adam

filter_length = 300

model = Sequential()
model.add(Embedding(max_words, 20, input_length=maxlen))
model.add(Dropout(0.1))
model.add(Conv1D(filter_length, 3, padding='valid', activation='relu', strides=1))
model.add(GlobalMaxPool1D())
model.add(Dense(num_classes))
model.add(Activation('sigmoid'))

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['categorical_accuracy'])
model.summary()

callbacks = [
    ReduceLROnPlateau(),
    EarlyStopping(patience=4),
    ModelCheckpoint(filepath='model-conv1d.h5', save_best_only=True)
]

history = model.fit(x_train, y_train,
                    class_weight=class_weight,
                    epochs=20,
                    batch_size=32,
                    validation_split=0.1,
                    callbacks=callbacks)

但是,在在线搜索之后,我只能在Keras网站here上找到GlobalMaxPooling1D。他们是一样的吗?如果没有,功能和用法有什么区别?

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

我要补充说的是,其他图层也可以使用,例如Conv2D == Convolution2D,MaxPooling2D == MaxPool2D。