oarfish
oarfish

Reputation: 4621

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.

Upvotes: 9

Views: 318

Answers (2)

oarfish
oarfish

Reputation: 4621

Turns out this is really a bug. https://github.com/tensorflow/tensorflow/issues/14886#issuecomment-352934112

Upvotes: 0

mikep
mikep

Reputation: 3895

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.

Upvotes: 4

Related Questions