0

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

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

4

1 回答 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
于 2020-04-22T20:34:05.163 回答