在训练过程中添加 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维度相同) . -
deltafloat,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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
