1.GlobalMaxPooling1D:
在steps维度对整个数据求最大值。
2.MaxPooling1D:
在steps维度求最大值。但是限制每一步的池化的大小。
实例:
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, LSTM, GlobalMaxPooling1D, MaxPooling1D
D = np.random.rand(10, 6, 10)
model = Sequential()
model.add(LSTM(16, input_shape=(6, 10), return_sequences=True))
model.add(MaxPooling1D(pool_size=2, strides=1))
model.add(LSTM(10))
model.add(Dense(1))
model.compile(loss='binary_crossentropy', optimizer='sgd')
# print the summary to see how the dimension change after the layers are
# applied
print(model.summary())
# try a model with GlobalMaxPooling1D now
model = Sequential()
model.add(LSTM(16, input_shape=(6, 10), return_sequences=True))
model.add(GlobalMaxPooling1D())
model.add(Dense(1))
model.compile(loss='binary_crossentropy', optimizer='sgd')
print(model.summary())
原文:
https://blog.csdn.net/linxid/article/details/86426506