张量流中的sigmoid_cross_entropy损失函数用于图像分割 [英] sigmoid_cross_entropy loss function from tensorflow for image segmentation

查看:460
本文介绍了张量流中的sigmoid_cross_entropy损失函数用于图像分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解sigmoid_cross_entropy损失函数对图像分割神经网络的作用:

I'm trying to understand what the sigmoid_cross_entropy loss function does with regards to image segmentation neural networks:

这里是相关的Tensorflow来源代码:

Here is the relevant Tensorflow source code:

zeros = array_ops.zeros_like(logits, dtype=logits.dtype)
cond = (logits >= zeros)
relu_logits = array_ops.where(cond, logits, zeros)
neg_abs_logits = array_ops.where(cond, -logits, logits)
return math_ops.add(
    relu_logits - logits * labels,
    math_ops.log1p(math_ops.exp(neg_abs_logits)), name=name)

我的主要问题是为什么退货时出现math_ops.add()?加法是指图像中每个像素的损失总和,还是总和有所不同?我无法正确地遵循尺寸变化来推断总和.

My main question is why is there a math_ops.add() at the return? Is the add referring to the summation of the loss for every pixel in the image or is the summation doing something different? I'm not able to properly follow the dimensional changes to deduce what the summation is doing.

推荐答案

sigmoid_cross_entropy_with_logits用于多标签分类.

对于独立的类别预测,整个问题可以分为二元交叉熵损失(例如1既是偶数又是素数).最后,收集所有预测损失并将其平均.

The whole problem can be divided into binary cross-entropy loss for the class predictions that are independent(e.g. 1 is both even and prime). Finaly collect all prediction loss and average them.

下面是一个示例:

import tensorflow as tf


logits = tf.constant([[0, 1],
                      [1, 1],
                      [2, -4]], dtype=tf.float32)
y_true = tf.constant([[1, 1],
                      [1, 0],
                      [1, 0]], dtype=tf.float32)
# tensorflow api
loss = tf.losses.sigmoid_cross_entropy(multi_class_labels=y_true,
                                       logits=logits)

# manul computing
probs = tf.nn.sigmoid(logits)
loss_t = tf.reduce_mean(y_true * (-tf.log(probs)) +
                        (1 - y_true) * (-tf.log(1 - probs)))

config = tf.ConfigProto()
config.gpu_options.allow_growth = True  # pylint: disable=no-member
with tf.Session(config=config) as sess:
    loss_ = loss.eval()
    loss_t_ = loss_t.eval()
    print('sigmoid_cross_entropy: {: .3f}\nmanual computing: {: .3f}'.format(
        loss_, loss_t_))
------------------------------------------------------------------------------
#output: 
    sigmoid_cross_entropy:  0.463
    manual computing:  0.463

这篇关于张量流中的sigmoid_cross_entropy损失函数用于图像分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆