【发布时间】:2019-04-10 23:01:49
【问题描述】:
在 Tensorflow 中,我在网络末端执行以下全局平均池化:
x_ = tf.reduce_mean(x, axis=[1,2])
我的张量x 的形状为(n, h, w, c),其中n 是输入的数量,w 和h 对应于宽度和高度尺寸,c 是通道/过滤器的数量.
从张量x 开始,在调用tf.reduce_mean() 之后,张量大小为(n, h, w, c),结果张量的大小为(n, c)。
我怎样才能扭转这个过程?如何进行 unpooling 操作?
编辑
这是一个没有按预期工作的示例:
import tensorflow as tf
import numpy as np
n, c = 1, 2
h, w = 2, 2
x = tf.ones([n, h, w, c])
y = tf.reduce_mean(x, axis=[1,2], keepdims=True)
z = tf.reshape(y, [n, 1, 1, c])
u = tf.tile(z, [n, h, w, c])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(x)
print("x", sess.run(x))
print("\n")
print(y)
print("y", sess.run(y))
print("\n")
print(z)
print("z", sess.run(z))
print("\n")
print(u)
print("u", sess.run(u))
输出是:
Tensor("ones:0", shape=(1, 2, 2, 2), dtype=float32)
x [[[[1. 1.]
[1. 1.]]
[[1. 1.]
[1. 1.]]]]
Tensor("Mean:0", shape=(1, 1, 1, 2), dtype=float32)
y [[[[1. 1.]]]]
Tensor("Reshape:0", shape=(1, 1, 1, 2), dtype=float32)
z [[[[1. 1.]]]]
Tensor("Tile:0", shape=(1, 2, 2, 4), dtype=float32)
u [[[[1. 1. 1. 1.]
[1. 1. 1. 1.]]
[[1. 1. 1. 1.]
[1. 1. 1. 1.]]]]
【问题讨论】:
标签: python tensorflow