import tensorflow as tf
temp = [0., 0., 1., 0., 0., 0., 1.5, 2.5]
# Reshape the tensor to be 3 dimensions.
values = tf.reshape(temp, [1, 8, 1])
# Use an averaging pool on the tensor.
p_avg = tf.nn.pool(input=values,
window_shape=[2],
pooling_type="AVG",
padding="SAME")
# Use max with this pool.
p_max = tf.nn.pool(input=values,
window_shape=[2],
pooling_type="MAX",
padding="SAME")
session = tf.Session()
# Print our tensors.
print("VALUES")
print(session.run(values))
print("POOL")
print(session.run(p_avg))
print("POOL MAX")
print(session.run(p_max))
session.close()
import tensorflow as tf
a=tf.constant([
[[1.0,2.0,3.0,4.0],
[5.0,6.0,7.0,8.0],
[8.0,7.0,6.0,5.0],
[4.0,3.0,2.0,1.0]],
[[4.0,3.0,2.0,1.0],
[8.0,7.0,6.0,5.0],
[1.0,2.0,3.0,4.0],
[5.0,6.0,7.0,8.0]]
])
a=tf.reshape(a,[1,4,4,2])
pooling=tf.nn.max_pool(a,[1,2,2,1],[1,1,1,1],padding='SAME')
with tf.Session() as sess:
print("image:")
image=sess.run(a)
print (image)
print("reslut:")
result=sess.run(pooling)
print (result)