当前位置 博文首页 > 斯人若彩虹,遇上方知有!:Pytorch-18种经典的损失函数

    斯人若彩虹,遇上方知有!:Pytorch-18种经典的损失函数

    作者:[db:作者] 时间:2021-08-25 21:50

    一、18种损失函数

    目录:

    一、18种损失函数

    1、nn.CrossEntropyLoss(交叉熵损失)

    2、nn.NLLLoss

    3、nn.BCELoss

    4、nn.BCEWithLogitsLoss

    5、nn.L1Loss

    6、nn.MSELoss

    7、nn.SmoothL1Loss

    8、PoissonNLLLoss

    9、nn.KLDivLoss

    10、nn.MarginRankingLoss

    11、nn.MultiLabelMarginLoss

    12、nn.SoftMarginLoss

    13、nn.MultiLabelSoftMarginLoss

    14、nn.MultiMarginLoss

    15、nn.TripletMarginLoss

    16、nn.HingeEmbeddingLoss

    17、nn.CosineEmbeddingLoss

    18、nn.CTCLoss



    损失函数:衡量模型输出与真实标签的差异;

    目标函数 = 代价函数 + 正则化项(L1或者L2等,惩罚项)

    1、nn.CrossEntropyLoss(交叉熵损失)

    (1)什么是熵?:熵是信息论中最基本、最核心的一个概念,它衡量了一个概率分布的随机程度,或者说包含的信息量的大小。

    具体公式推导可以参考这篇博主的讲解:一文搞懂交叉损失,讲解浅显易懂!

    (2)功能: nn.LogSoftmax ()与nn.NLLLoss ()结合,进行 交叉熵计算 cs