codecamp

TensorFlow函数:tf.losses.sparse_softmax_cross_entropy

tf.losses.sparse_softmax_cross_entropy函数

tf.losses.sparse_softmax_cross_entropy(
    labels,
    logits,
    weights=1.0,
    scope=None,
    loss_collection=tf.GraphKeys.LOSSES,
    reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)

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

使用tf.nn.sparse_softmax_cross_entropy_with_logits的交叉熵(cross-entropy)loss.

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

参数:

  • labels:形状为[d_0, d_1, ..., d_{r-1}]的Tensor(其中,r是labels和结果的秩),并且有dtype int32或int64.labels中的每个条目必须是[0, num_classes)中的索引.当此操作在CPU上运行时,其他值将引发异常,并返回NaNGPU上相应的loss和梯度行.
  • logits:形状为[d_0, d_1, ..., d_{r-1}, num_classes],并且是dtype float32或float64的未缩放的日志概率.
  • weights:loss的系数.这必须是标量或可广播的labels(即相同的秩,每个维度是1或者是相同的).
  • scope:计算loss时执行的操作范围.
  • loss_collection:将添加loss的集合.
  • reduction:适用于loss的减少类型.

返回:

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

可能引发的异常:

  • ValueError:如果logits,labels和weights的形状不兼容,或者如果它们中的任何一个为None.
TensorFlow函数:tf.losses.softmax_cross_entropy
TensorFlow模块:tf.math
温馨提示
下载编程狮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; }