📅  最后修改于: 2023-12-03 15:17:08.191000             🧑  作者: Mango
The MaxPool2D
layer in Keras is used for max pooling operation for 2D spatial data. It is typically used to reduce the dimensionality of feature maps by extracting the most important feature activations from them. Max pooling is a type of operation that selects the maximum elements from a set of values.
The MaxPool2D layer accepts the following parameters:
pool_size
: integer or tuple of two integers, specifying the pooling size in both dimensions (e.g. (2, 2)
).strides
: integer or tuple of two integers, specifying the stride length in both dimensions. Default is (1, 1)
which means no overlapping.padding
: One of "valid"
or "same"
. Default is "valid"
.data_format
: one of "channels_last"
(default) or "channels_first"
. The ordering of the dimensions in the inputs. "channels_last"
means that the input shape is (batch, height, width, channels)
while "channels_first"
means that the input shape is (batch, channels, height, width)
.Example usage:
from keras.models import Sequential
from keras.layers import Conv2D, MaxPool2D, Flatten, Dense
model = Sequential([
Conv2D(filters=32, kernel_size=(3,3), input_shape=(28,28,1), activation='relu'),
MaxPool2D(pool_size=(2,2)),
Flatten(),
Dense(10, activation='softmax')
])
In the above example, after the Conv2D layer, the MaxPool2D layer is used with a pooling size of (2,2)
. This reduces the dimensionality of feature maps by half.