tf.nn.sparse_softmax_cross_entropy_with_logits

简介:
相当于合并了softmax和cross_entropy两步
sparse_softmax_cross_entropy_with_logits(_sentinel=None, labels=None, logits=None, name=None)
    Computes sparse softmax cross entropy between `logits` and `labels`.
    
    Measures the probability error in discrete classification tasks in which the
    classes are mutually exclusive (each entry is in exactly one class).  For
    example, each CIFAR-10 image is labeled with one and only one label: an image
    can be a dog or a truck, but not both.
    
    **NOTE:**  For this operation, the probability of a given label is considered
    exclusive.  That is, soft classes are not allowed, and the `labels` vector
    must provide a single specific index for the true class for each row of
    `logits` (each minibatch entry).  For soft softmax classification with
    a probability distribution for each entry, see
    `softmax_cross_entropy_with_logits`.
    
    **WARNING:** This op expects unscaled logits, since it performs a `softmax`
    on `logits` internally for efficiency.  Do not call this op with the
    output of `softmax`, as it will produce incorrect results.
    
    A common use case is to have logits of shape `[batch_size, num_classes]` and
    labels of shape `[batch_size]`. But higher dimensions are supported.
    
    **Note that to avoid confusion, it is required to pass only named arguments to
    this function.**
    
    Args:
      _sentinel: Used to prevent positional parameters. Internal, do not use.
      labels: `Tensor` of shape `[d_0, d_1, ..., d_{r-1}]` (where `r` is rank of
        `labels` and result) and dtype `int32` or `int64`. Each entry in `labels`
        must be an index in `[0, num_classes)`. Other values will raise an
        exception when this op is run on CPU, and return `NaN` for corresponding
        loss and gradient rows on GPU.
      logits: Unscaled log probabilities of shape
        `[d_0, d_1, ..., d_{r-1}, num_classes]` and dtype `float32` or `float64`.
      name: A name for the operation (optional).
    
    Returns:
      A `Tensor` of the same shape as `labels` and of the same type as `logits`
      with the softmax cross entropy loss.
    
    Raises:
      ValueError: If logits are scalars (need to have rank >= 1) or if the rank
        of the labels is not equal to the rank of the logits minus one.
目录
相关文章
|
8月前
|
机器学习/深度学习 PyTorch 算法框架/工具
归一化技术比较研究:Batch Norm, Layer Norm, Group Norm
本文将使用合成数据集对三种归一化技术进行比较,并在每种配置下分别训练模型。记录训练损失,并比较模型的性能。
442 2
|
8月前
|
机器学习/深度学习 资源调度 监控
PyTorch使用Tricks:Dropout,R-Dropout和Multi-Sample Dropout等 !!
PyTorch使用Tricks:Dropout,R-Dropout和Multi-Sample Dropout等 !!
124 0
|
5月前
|
机器学习/深度学习 Python
tf.keras.layers.LSTM/tf.keras.layers.LSTMCell
【8月更文挑战第20天】tf.keras.layers.LSTM/tf.keras.layers.LSTMCell。
50 1
|
28天前
|
机器学习/深度学习 PyTorch 算法框架/工具
详解三种常用标准化Batch Norm & Layer Norm & RMSNorm
通过本文的介绍,希望您能够深入理解Batch Norm、Layer Norm和RMSNorm的原理和实现,并在实际应用中灵活选择和使用,提升深度学习模型的性能和稳定性。
369 5
|
5月前
tf.keras.layers.Dense
【8月更文挑战第20天】tf.keras.layers.Dense。
96 2
|
5月前
|
算法框架/工具 数据格式
tf.keras.layers.Conv2D
【8月更文挑战第20天】tf.keras.layers.Conv2D。
63 2
|
5月前
tf.zeros(), tf.zeros_like(), tf.ones(),tf.ones_like()
【8月更文挑战第11天】tf.zeros(), tf.zeros_like(), tf.ones(),tf.ones_like()。
57 5
|
机器学习/深度学习 PyTorch 算法框架/工具
|
SQL PyTorch 算法框架/工具
pytorch损失函数binary_cross_entropy和binary_cross_entropy_with_logits的区别
binary_cross_entropy和binary_cross_entropy_with_logits都是来自torch.nn.functional的函数
1658 0
|
数据采集 机器学习/深度学习
tebsorflow2.0 tf.keras序列问题
本节是主要介绍的是序列问题的处理,采用的数据集为电影评论数据集,我们通过keras.datasets.imdb直接导入,之后我们建立模型,对其进行分类,并处理过拟合问题。
136 0
tebsorflow2.0 tf.keras序列问题

热门文章

最新文章