TensorFlow:为什么 avg_pool 忽略一步维度?
TensorFlow: Why does avg_pool ignore one stride dimension?
我试图跨过通道维度,但以下代码表现出令人惊讶的行为。我期望 tf.nn.max_pool
和 tf.nn.avg_pool
在输入完全相同的参数时应该产生相同形状的张量。事实并非如此。
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)
这会打印
$ python ex04/mini.py
(100, 16, 16, 32)
(100, 16, 16, 64)
显然,我误会了什么。
link https://github.com/Hvass-Labs/TensorFlow-Tutorials/issues/19 状态:
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.
事实证明这确实是一个错误。
https://github.com/tensorflow/tensorflow/issues/14886#issuecomment-352934112
我试图跨过通道维度,但以下代码表现出令人惊讶的行为。我期望 tf.nn.max_pool
和 tf.nn.avg_pool
在输入完全相同的参数时应该产生相同形状的张量。事实并非如此。
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)
这会打印
$ python ex04/mini.py
(100, 16, 16, 32)
(100, 16, 16, 64)
显然,我误会了什么。
link https://github.com/Hvass-Labs/TensorFlow-Tutorials/issues/19 状态:
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.
事实证明这确实是一个错误。 https://github.com/tensorflow/tensorflow/issues/14886#issuecomment-352934112