前导k池元素的最佳方法是什么,而不仅仅是Tensorflow中的最大元素?

Jim*_*ang 9 python tensorflow

现在tensorflow中的最大池函数是

tf.nn.max_pool(value, ksize, strides, padding, name=None)
Returns:
A Tensor with type tf.float32. The max pooled output tensor.

我想有一个扩展版本的max_pool,比如

tf.nn.top_k_pool(value, ksize, strides, padding, k=1, name=None)

Performs the top k pooling on the input.

Args:

value: A 4-D Tensor with shape [batch, height, width, channels] and type tf.float32.
ksize: A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.
strides: A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.
padding: A string, either 'VALID' or 'SAME'. The padding algorithm.
k: 0-D int32 Tensor. Number of top elements to look in each pool.
name: Optional name for the operation.
Returns:

A Tensor with type tf.float32. The max pooled output tensor. There will be an additional dimension saving the top k values.

我知道我可以在https://www.tensorflow.org/versions/r0.7/how_tos/adding_an_op/index.html之后花费tensorflow操作

我想知道是否有更简单的方法来实现这一目标.

gda*_*ahl 1

你最好的选择可能是 TopK 操作: https: //www.tensorflow.org/versions/r0.7/api_docs/python/nn.html#top_k

  • 您能展示一段代码来实现它吗?事实上,我已经看过该函数,但我无法想象将其实现为池化的方法,因为我必须处理池窗口。 (2认同)