codecamp

TensorFlow函数:tf.losses.softmax_cross_entropy

tf.losses.softmax_cross_entropy函数

tf.losses.softmax_cross_entropy(
    onehot_labels,
    logits,
    weights=1.0,
    label_smoothing=0,
    scope=None,
    loss_collection=tf.GraphKeys.LOSSES,
    reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)

定义在:tensorflow/python/ops/losses/losses_impl.py.

使用tf.nn.softmax_cross_entropy_with_logits创建交叉熵(cross-entropy)loss.

weights作为loss的系数.如果提供了标量,那么loss只是按给定值缩放.如果weights是形状为[batch_size]的张量,则loss权重适用于每个相应的样本.

如果label_smoothing非零,则将标签平滑为:1/num_classes: new_onehot_labels = onehot_labels * (1 - label_smoothing) + label_smoothing / num_classes

参数:

  • onehot_labels:[batch_size, num_classes]目标是一个hot-encoded标签.
  • logits:[batch_size, num_classes]logits网络的输出.
  • weights:可选的Tensor,其秩为0或1,并且可以广播到形状为[batch_size]的Tensor的loss.
  • label_smoothing:如果大于0,则平滑标签.
  • scope:计算loss时执行的操作范围.
  • loss_collection:将添加loss的集合.
  • reduction:适用于loss的减少类型.

返回:

与logits具有相同类型的加权损失Tensor.如果reduction是NONE,这有形状[batch_size];否则,它是标量.

可能引发的异常:

  • ValueError:如果logits的形状与onehot_labels不匹配,或weights的形状无效,或者如果weights是None,如果onehot_labels或logits是None.
TensorFlow函数:tf.losses.sigmoid_cross_entropy
TensorFlow函数:tf.losses.sparse_softmax_cross_entropy
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }