diff --git a/tensorflow/python/keras/layers/pooling.py b/tensorflow/python/keras/layers/pooling.py index aab56bdf55e..e592eaf4959 100644 --- a/tensorflow/python/keras/layers/pooling.py +++ b/tensorflow/python/keras/layers/pooling.py @@ -370,6 +370,24 @@ class MaxPooling2D(Pooling2D): [[10.], [11.], [12.]]]], dtype=float32)> + + Usage Example: + + >>> input_image = tf.constant([[[[1.], [1.], [2.], [4.]], + ... [[2.], [2.], [3.], [2.]], + ... [[4.], [1.], [1.], [1.]], + ... [[2.], [2.], [1.], [4.]]]]) + >>> output = tf.constant([[[[1], [0]], + ... [[0], [1]]]]) + >>> model = tf.keras.models.Sequential() + >>> model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2), + ... input_shape=(4,4,1))) + >>> model.compile('adam', 'mean_squared_error') + >>> model.predict(input_image, steps=1) + array([[[[2.], + [4.]], + [[4.], + [4.]]]], dtype=float32) For example, for stride=(1,1) and padding="same":