具有未知形状的张量流中的空间金字塔池

问题描述 投票:0回答:1

我想在张量流中执行空间金字塔池化。 there(以及Stackoverflow.com中的其他问题)已经回答了这个问题,但是建议的解决方案不适用于未知的输入形状。

是否有实现在图形定义时处理未知形状的实现?

tensorflow spatial-pooling
1个回答
0
投票

为了解决此问题,我想出了一个使用掩码的不同实现,并使用最近的邻居对其进行了重新缩放:

def avg_spp(self, input, scale, name, padding=DEFAULT_PADDING):
    eye = tf.eye(scale*scale, batch_shape=(tf.shape(input)[0],))
    mask = tf.reshape(eye, (-1, scale, scale, scale*scale))
    mask = tf.image.resize_nearest_neighbor(mask, tf.shape(input)[1:3])
    spp = tf.multiply(tf.expand_dims(input, 4), tf.expand_dims(mask, 3))
    spp = tf.divide(tf.reduce_sum(spp, axis=[1,2]), tf.cast(tf.count_nonzero(spp, axis=[1,2]), tf.float32))
    spp = tf.reshape(spp, (-1, tf.shape(input)[3], scale, scale))
    spp = tf.transpose(spp, [0,2,3,1], name=name)
    return spp
© www.soinside.com 2019 - 2024. All rights reserved.