gpt4 book ai didi

python-3.x - TensorFlow:为什么avg_pool忽略一个步幅维度?

转载 作者:行者123 更新时间:2023-12-04 04:24:08 25 4
gpt4 key购买 nike

我试图跨越 channel 维度,并且以下代码表现出令人惊讶的行为。我期望tf.nn.max_pooltf.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)

显然,我误会了一些东西。

最佳答案

链接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.

关于python-3.x - TensorFlow:为什么avg_pool忽略一个步幅维度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47423172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com