Another option is to use the tf.nn.pool function. Assuming the input is of the form [batch_size, length, num_channels], the function can be used as:
B = tf.nn.pool(A, [size], 'MAX', 'SAME', strides = [stride])
As an example, the matrix of the form [8, 10, 1] is transformed into [8, 2, 1] using the maximum union.
[[[0, 1, ... 9]], [[[4, 9]], [[0, 1, ..., 9]], ---> [[4, 9]], ..., ..., [[0, 1, ..., 9]]] [[4, 9]]]
Python Code:
import numpy as np import tensorflow as tf X = np.tile(np.arange(10), 8).reshape(8, 10, 1) A = tf.Variable(X) B = tf.nn.pool(A, [5], 'MAX', 'SAME', strides = [5]) sess = tf.Session() init = tf.global_variables_initializer() sess.run(init) sess.run([B]) C = B.eval(session = sess) print(C)