9

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.

oarfish
  • 3,240
  • 4
  • 25
  • 54

2 Answers2

4

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.

mikep
  • 3,631
  • 6
  • 20
  • 1
    Clearly, _must_ is overstated then, since it just silently runs instead of erroring. It seems I must file a bug report. – oarfish Nov 24 '17 at 13:50
0

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

oarfish
  • 3,240
  • 4
  • 25
  • 54