tf.nn.sigmoid_cross_entropy_with_logits

tf.nn.sigmoid_cross_entropy_with_logits(_sentinel=None, labels=None, logits=None, name=None)

Docstring:

Computes sigmoid cross entropy given logits.

Type: function

Measures the probability error in discrete classification tasks in which each class is independent and not mutually exclusive. For instance, one could perform multilabel classification where a picture can contain both an elephant and a dog at the same time.

sigmoid搭配使用的交叉熵损失函数,输入不需要额外加一层sigmoidtf.nn.sigmoid_cross_entropy_with_logits中会集成有sigmoid并进行了计算优化;它适用于分类的类别之间不是相互排斥的场景,即多个标签(如图片中包含狗和猫)。

For brevity, let x = logits, z = labels. The logistic loss is

  z * -log(sigmoid(x)) + (1 - z) * -log(1 - sigmoid(x))
= z * -log(1 / (1 + exp(-x))) + (1 - z) * -log(exp(-x) / (1 + exp(-x)))
= z * log(1 + exp(-x)) + (1 - z) * (-log(exp(-x)) + log(1 + exp(-x)))
= z * log(1 + exp(-x)) + (1 - z) * (x + log(1 + exp(-x))
= (1 - z) * x + log(1 + exp(-x))
= x - x * z + log(1 + exp(-x))

For x < 0, to avoid overflow in exp(-x), we reformulate the above

  x - x * z + log(1 + exp(-x))
= log(exp(x)) - x * z + log(1 + exp(-x))
= - x * z + log(1 + exp(x))

Hence, to ensure stability and avoid overflow, the implementation uses this equivalent formulation

max(x, 0) - x * z + log(1 + exp(-abs(x)))

logits and labels must have the same type and shape.

Args:

_sentinel: Used to prevent positional parameters. Internal, do not use.
labels: A Tensor of the same type and shape as logits.
logits: A Tensor of type float32 or float64.
name: A name for the operation (optional).

Returns:

A Tensor of the same shape as logits with the componentwise logistic losses.

Raises:

ValueError: If logits and labels do not have the same shape.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 白天得一空闲 穿过小街 到达目的地 我们走了一圈 发现了这个拍照的好地儿 一排红砖围墙 院子里种的是葡萄树
    白瑪_ceaf阅读 132评论 0 0
  • 1.感谢棒棒的自己,带领大家跳舞,准备节目,加油!谢谢!谢谢!谢谢! 2.感谢我的抵抗力,抵抗着雾霾,谢谢!谢谢!...
    景小牛阅读 175评论 0 0
  • 时隔多日,再次下载这个软件,我不想打破眼前的平静。我在想一件事,我这样继续贴近她,到底是为什么。坊间到处流传着她和...
    浅梦Shallow丶阅读 162评论 0 0
  • 在浩瀚的宇宙中,太阳孤独,月亮孤独,而星星有许多许多,无以数计,有名的星少,如北斗星,牛郎星,织女星,无名的很多…...
    云淡风清_648d阅读 309评论 0 0