【问题标题】:Per pixel softmax for fully convolutional network全卷积网络的每像素 softmax
【发布时间】:2016-08-19 10:21:56
【问题描述】:

我正在尝试实现类似完全卷积网络的东西,其中最后一个卷积层使用 1x1 的滤波器大小并输出一个“分数”张量。分数张量的形状为 [Batch, height, width, num_classes]。

我的问题是,tensorflow 中的什么函数可以对每个像素应用 softmax 操作,独立于其他像素。 tf.nn.softmax 操作似乎不是为了这个目的。

如果没有这样的操作可用,我想我必须自己写一个。

谢谢!

更新:如果我必须自己实现,我想我可能需要将输入张量重塑为 [N, num_claees],其中 N = Batch x width x height,并应用 tf.nn.softmax,然后将其重新整形.有意义吗?

【问题讨论】:

  • 您可以将其重塑为 2d 矩阵,进行 softmax,然后重新整形。
  • 啊哈,和你的 cmets 同时更新。不过谢谢!
  • 嘿,你终于实现了吗?我被困在这里了。

标签: tensorflow image-segmentation softmax


【解决方案1】:

你可以使用这个功能。

我是通过搜索GitHub找到的。

import tensorflow as tf

"""
Multi dimensional softmax,
refer to https://github.com/tensorflow/tensorflow/issues/210
compute softmax along the dimension of target
the native softmax only supports batch_size x dimension
"""
def softmax(target, axis, name=None):
    with tf.name_scope(name, 'softmax', values=[target]):
        max_axis = tf.reduce_max(target, axis, keep_dims=True)
        target_exp = tf.exp(target-max_axis)
        normalize = tf.reduce_sum(target_exp, axis, keep_dims=True)
        softmax = target_exp / normalize
        return softmax

【讨论】:

【解决方案2】:

将其重塑为 2d,然后再将其重新整形,就像您猜到的那样,是正确的方法。

【讨论】:

    猜你喜欢
    • 2019-02-11
    • 2016-11-13
    • 2016-12-27
    • 2019-01-13
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 2018-11-28
    相关资源
    最近更新 更多