Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow:撤消全局平均池_Python_Tensorflow - Fatal编程技术网

Python Tensorflow:撤消全局平均池

Python Tensorflow:撤消全局平均池,python,tensorflow,Python,Tensorflow,在Tensorflow中,我在网络末端执行以下全局平均池: x_ = tf.reduce_mean(x, axis=[1,2]) 我的张量x的形状为(n,h,w,c),其中n是输入的数量,w和h对应于宽度和高度尺寸,c是通道/过滤器的数量 在调用tf.reduce_mean()之后,以大小为(n,h,w,c)的张量x开始。得到的张量大小为(n,c) 我怎样才能扭转这个过程?我怎样才能进行脱冷操作 编辑 以下是一个未按预期工作的示例: import tensorflow as tf import

在Tensorflow中,我在网络末端执行以下全局平均池:

x_ = tf.reduce_mean(x, axis=[1,2])
我的张量
x
的形状为
(n,h,w,c)
,其中
n
是输入的数量,
w
h
对应于宽度和高度尺寸,
c
是通道/过滤器的数量

在调用
tf.reduce_mean()
之后,以大小为
(n,h,w,c)
的张量
x
开始。得到的张量大小为
(n,c)

我怎样才能扭转这个过程?我怎样才能进行脱冷操作

编辑

以下是一个未按预期工作的示例:

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.]]]]

您可以使用
tf.reforme
tf.tile
执行取消冷却操作

x = tf.random_uniform([n, c])
y = tf.reshape(x, [n, 1, 1, c])
z = tf.tile(y, [1, h, w, 1])

在调用
tf.reformate
tf.tile
后,以大小为
x
(n,c)的张量开始,得到的张量
z
大小为
(n,h,w,c)
,当我测试你的答案时,张量
z
大小为
[n*n,h,w,c]/code>?如何检查去冷操作是否正常工作?显示张量形状。打印(z.shape)我添加了一个示例对不起,瓷砖被修改了并修改了。