zoukankan      html  css  js  c++  java
  • 深度之眼PyTorch训练营第二期 --- 9、损失函数

    一、损失函数概念

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

    • 损失函数Loss Function :Loss = f(y^ , y)
    • 代价函数Cost Function:Cost = 1/N ∑ f (y^ , y)
    • 目标函数Objective Function:Obj = Cost + Regularization

                    

    二、交叉熵损失函数

    三、NLL   BCE BCEWithLogits Loss.

    1、nn.CrossEntropyLoss

    • 功能:nn.LogSoftmax()与nn.NLLLoss()结合,进行交叉熵计算  数据值进行归一化
    • 主要参数:
      • weight:各类别的loss设置权值
      • ignore_index:忽略某个类别
      • reduction:计算模式
    • 交叉熵 = 信息熵 + 相对熵
    • 交叉熵:
    • 自信息
    • 相对熵:两个分部之间的差异,不具备对称性

    5、nn.L1Loss

    功能:计算inputs与target之差的绝对值

    6、nn.MSELoss

    功能:计算inputs与target之差的平方

    主要参数:reduction:计算模式,可为none/sum/mean

    none:逐个元素计算

    sum:所有元素求和,返回标量

    mean:加权平均,返回标量

    7、nn.SmoothL1Loss

    8、nn.PoissonNULLLoss

    功能:泊松分布的负对数似然损失函数

    主要参数:log_input:输入是否为对数形式,决定计算公式

    full:计算所有loss,默认为False

    eps:修正项,避免log(input)为nan

    9、nn.KLDivLoss

    功能:计算KLD(divergence),KL散度,相对熵

    注意事项:需提前将输入计算log-probabilities,如通过nn.logsoftmax()

    主要参数:

    reduction:none/sum/mean/batchmean

    batchmean-batchsize维度求平均值

    10、nn.MarginRankingLoss

    功能:计算两个向量之间的相似度,用于排序任务

    特别说明:该方法计算两组数据之间的差异,返回一个n*n的loss矩阵

    主要参数:

    margin:边界值,x1和x2之间的差异值

    reduction:计算模式,可为none/sum/mean

    11、nn.MultiLabelSoftMarginLoss

    12、nn.SoftMarginLoss

    功能:计算二分类的logistic损失

    主要参数:reduction

    13、nn.MultiLabelSoftMarginLoss

    功能:SoftMarginLoss多标签版本

    主要参数:weight:各类别的loss设置权限

    reduction:

    14、nn.MultiMarginLoss

    功能:计算多分类的折页损失

    主要参数:p:可选1或2

    weight:

    margin:边界值

    reduction

    15、nn.TripletMarginLoss

    功能:计算三元组损失,人脸验证中常用

    主要参数:p margin reduction

    16、nn.HingeEmbeddingLoss

    功能:计算两个输入的相似性,常用于非线性embedding和半监督学习

    特别注意:输入x应为两个输入之差的绝对值

    主要参数:margin reduction

    17、nn.CosineEmbeddingLoss

    功能:采用余弦相似度计算两个输入的相似性

    主要参数:margin reduction

    18、nn.CTCLoss

    功能:计算CTC损失,解决时序类数据的分类Connctionist Temporal Classification

    主要参数:blank:blank label

    zero_infinity:无穷大的值或梯度置0

    reduction

  • 相关阅读:
    State模式
    Visitor模式,Decorator模式,Extension Object模式
    系统报错undefine not symbol armv7
    decompressedResponseImageOfSize:completionHandler:]_block_invoke
    App Transport Security has blocked a cleartext HTTP
    UIButton 左对齐 省略号最右边
    ActiveAndroid问题no such table解决总结
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
    fun下载内容批量收集
    The `brew link` step did not complete successfully
  • 原文地址:https://www.cnblogs.com/cola-1998/p/11818380.html
Copyright © 2011-2022 走看看