快捷方式

HuberLoss

class torch.nn.HuberLoss(reduction='mean', delta=1.0)[source][source]

創建一個準則,如果絕對元素誤差小於 delta,則使用平方項;否則使用 delta 縮放的 L1 項。此損失結合了 L1LossMSELoss 的優點;與 MSELoss 相比,delta 縮放的 L1 區域使損失對離群值不太敏感,而 L2 區域在 0 附近提供了比 L1Loss 更好的平滑性。有關更多資訊,請參閱 Huber loss

對於大小為 NN 的批次,未縮減的損失可以描述為

(x,y)=L={l1,...,lN}T\ell(x, y) = L = \{l_1, ..., l_N\}^T

其中

ln={0.5(xnyn)2,if xnyn<deltadelta(xnyn0.5delta),otherwise l_n = \begin{cases} 0.5 (x_n - y_n)^2, & \text{if } |x_n - y_n| < delta \\ delta * (|x_n - y_n| - 0.5 * delta), & \text{otherwise } \end{cases}

如果 reduction 不是 none,則

(x,y)={mean(L),if reduction=‘mean’;sum(L),if reduction=‘sum’.\ell(x, y) = \begin{cases} \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} \end{cases}

注意

當 delta 設定為 1 時,此損失等同於 SmoothL1Loss。 一般來說,此損失與 SmoothL1Loss 的差異在於 delta 因子(在 Smooth L1 中又稱為 beta)。 有關這兩種損失之間行為差異的更多討論,請參閱 SmoothL1Loss

參數
  • reduction (str, optional) – 指定要應用於輸出的 reduction 方式:'none' | 'mean' | 'sum''none':不進行 reduction,'mean':輸出總和將除以輸出中的元素數量,'sum':將對輸出進行總和。 預設值:'mean'

  • delta (float, optional) – 指定在 delta 比例 L1 和 L2 損失之間變更的閾值。 該值必須為正數。 預設值:1.0

形狀
  • 輸入: ()(*) 其中 * 表示任意數量的維度。

  • 目標: ()(*), 與輸入相同的形狀。

  • 輸出: 標量。 如果 reduction'none', 則 ()(*), 與輸入相同的形狀。

文件

存取 PyTorch 的完整開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源