Example code

The following code demonstrates max pooling on a tensor using a VALID padding scheme:

import tensorflow as tfbatch_size=1input_height = 3input_width = 3input_channels = 1def main():  sess = tf.InteractiveSession()  layer_input = tf.constant([    [     [[1.0], [0.2], [2.0]],     [[0.1], [1.2], [1.4]],     [[1.1], [0.4], [0.4]]    ]   ])# The strides will look at the entire input by using the image_height and image_widthkernel = [batch_size, input_height, input_width, input_channels]max_pool = tf.nn.max_pool(layer_input, kernel, [1, 1, 1, 1], "VALID")print(sess.run(max_pool))if __name__ == '__main__':  main()

The output of the preceding listing will give the maximum values in the window 3 x 3 x 1:

[[[[ 2.]]]]

The following diagram explains how max pool ...

Get Neural Network Programming with TensorFlow now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.