Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow: Why does avg_pool ignore one stride dimension?

I am attempting to stride over the channel dimension, and the following code exhibits surprising behaviour. It is my expectation that tf.nn.max_pool and tf.nn.avg_pool should produce tensors of identical shape when fed the exact same arguments. This is not the case.

import tensorflow as tf

x = tf.get_variable('x', shape=(100, 32, 32, 64),
        initializer=tf.constant_initializer(5), dtype=tf.float32)
ksize = (1, 2, 2, 2)
strides = (1, 2, 2, 2)
max_pool = tf.nn.max_pool(x, ksize, strides, padding='SAME')
avg_pool = tf.nn.avg_pool(x, ksize, strides, padding='SAME')
print(max_pool.shape)
print(avg_pool.shape)

This prints

$ python ex04/mini.py 
(100, 16, 16, 32)
(100, 16, 16, 64)

Clearly, I am misunderstanding something.

like image 797
oarfish Avatar asked Nov 21 '17 21:11

oarfish


1 Answers

The link https://github.com/Hvass-Labs/TensorFlow-Tutorials/issues/19 states:

The first and last stride must always be 1, because the first is for the image-number and the last is for the input-channel.

like image 191
mikep Avatar answered Oct 05 '22 05:10

mikep