在訓練過程中添加 Huber Loss 項。
用法
tf.compat.v1.losses.huber_loss(
labels, predictions, weights=1.0, delta=1.0, scope=None,
loss_collection=tf.GraphKeys.LOSSES, reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)
參數
-
labels
地麵實況輸出張量,與'predictions' 的維度相同。 -
predictions
預測的輸出。 -
weights
可選Tensor
,其秩為0,或與labels
相同的秩,並且必須可廣播到labels
(即,所有維度必須是1
,或與相應的losses
維度相同) . -
delta
float
,Huber損失函數從二次變為線性的點。 -
scope
在計算損失時執行的操作的範圍。 -
loss_collection
將添加損失的集合。 -
reduction
適用於損失的減免類型。
返回
-
加權損失浮點數
Tensor
。如果reduction
是NONE
,則其形狀與labels
相同;否則,它是標量。
拋出
-
ValueError
如果predictions
的形狀與labels
的形狀不匹配或weights
的形狀無效。此外,如果labels
或predictions
為無。
對於 error=labels-predictions
中的每個值 x,計算如下:
0.5 * x^2 if |x| <= d
0.5 * d^2 + d * (|x| - d) if |x| > d
其中 d 是 delta
。
weights
作為損失的係數。如果提供了標量,則損失隻是按給定值縮放。如果 weights
是大小為 [batch_size]
的張量,則批次的每個樣本的總損失將由 weights
向量中的相應元素重新縮放。如果 weights
的形狀與 predictions
的形狀匹配,則 predictions
的每個可測量元素的損失將按 weights
的相應值進行縮放。
eager模式兼容性
loss_collection
參數在即刻執行時被忽略。考慮保持返回值或通過 tf.keras.Model
收集損失。
相關用法
- Python tf.compat.v1.losses.softmax_cross_entropy用法及代碼示例
- Python tf.compat.v1.losses.mean_squared_error用法及代碼示例
- Python tf.compat.v1.losses.sigmoid_cross_entropy用法及代碼示例
- Python tf.compat.v1.lookup.StaticHashTable用法及代碼示例
- Python tf.compat.v1.lookup.StaticVocabularyTable用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.layers.Conv3D用法及代碼示例
- Python tf.compat.v1.layers.dense用法及代碼示例
- Python tf.compat.v1.layers.AveragePooling3D用法及代碼示例
- Python tf.compat.v1.lite.TFLiteConverter用法及代碼示例
- Python tf.compat.v1.layers.Conv2DTranspose用法及代碼示例
- Python tf.compat.v1.layers.max_pooling3d用法及代碼示例
- Python tf.compat.v1.layers.average_pooling1d用法及代碼示例
- Python tf.compat.v1.layers.experimental.keras_style_scope用法及代碼示例
- Python tf.compat.v1.layers.flatten用法及代碼示例
- Python tf.compat.v1.layers.conv1d用法及代碼示例
- Python tf.compat.v1.layers.experimental.set_keras_style用法及代碼示例
- Python tf.compat.v1.layers.conv2d_transpose用法及代碼示例
- Python tf.compat.v1.layers.dropout用法及代碼示例
- Python tf.compat.v1.layers.batch_normalization用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.losses.huber_loss。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。