zoukankan      html  css  js  c++  java
  • TensorFlow/Keras binary_crossentropy损失函数

    In [22]: y_true = [[0], [1]]                                                                                                                                                
    In [23]: y_pred = [[0.9], [0.9]]                                                                                                                                            
    In [24]: tf.keras.losses.binary_crossentropy(y_true, y_pred)                                                                                                                
    Out[24]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([2.302584  , 0.10536041], dtype=float32)>
    In [25]: y_true = [[0, 1], [1, 0]]                                                                                                                                          
    In [26]: y_pred = [[0.9, 0.1], [0.9, 0.1]]                                                                                                                                  
    In [27]: tf.keras.losses.binary_crossentropy(y_true, y_pred)                                                                                                                
    Out[27]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([2.3025842 , 0.10536041], dtype=float32)>
    

    所以不管是不是 one-hot encoding 都可以使用, 得到的 loss 是一样的.

  • 相关阅读:
    ASP.NET
    JS、JQury
    ASP.NET
    ASP.NET
    ASP.NET
    C#
    C#
    C#
    基础算法-树:预备知识
    开发环境配置--Ubuntu+Qt4+OpenCV(二)
  • 原文地址:https://www.cnblogs.com/yaos/p/14014115.html
Copyright © 2011-2022 走看看