jingous

交叉熵损失函数之前是否需要加 softmax 函数?

  •  
  •   jingous · Apr 9, 2019 · 4185 views
    This topic created in 2616 days ago, the information mentioned may be changed or developed.

    在我的理解里面,交叉熵( cross-entry)损失函数中的 log 能够抵消 softmax 函数中的 exp.使得梯度能够更好的反向传播。
    在看 niftyNet 代码的时候,发现如下内容:
    在__init__中:

        if data_loss_function_name.startswith('cross_entropy') \
                or 'xent' in data_loss_function_name:
            tf.logging.info(
                'Cross entropy loss function calls '
                'tf.nn.sparse_softmax_cross_entropy_with_logits '
                'which always performs a softmax internally.')
            self._softmax = False
    

    在 layer_op 中

                    if self._softmax:
                        pred_b = tf.cast(pred_b, dtype=tf.float32)
                        pred_b = tf.nn.softmax(pred_b)
    

    为什么损失函数是 cross_entropy 的时候,不需要进行 softmax?

    4 replies    2019-04-10 10:18:10 +08:00
    dinghow
        1
    dinghow  
       Apr 9, 2019
    ![]( https://dinghow.site/2018/11/28/Udacity-DL-note1/dl-2.png)
    ![]( https://dinghow.site/2018/11/28/Udacity-DL-note1/dl-1.png)
    应该是要加的,利用 cross_entropy 来计算 softmax 层输出与 label 的 loss
    dinghow
        2
    dinghow  
       Apr 9, 2019
    @dinghow 囧,至于楼主的疑问,我也母鸡,期待有大神来解答
    tinywhale
        3
    tinywhale  
       Apr 10, 2019
    我记得 tf.nn.sparse_softmax_cross_entropy_with_logits 已经包括了 softmax
    jingous
        4
    jingous  
    OP
       Apr 10, 2019
    @tinywhale 似乎是这样的,谢谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2798 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:15 · PVG 20:15 · LAX 05:15 · JFK 08:15
    ♥ Do have faith in what you're doing.