def absolute_difference(weights=1.0, name='AbsoluteDifference', scope=None, collect=True):
"""Adds an Absolute Difference loss to the training procedure.
`weights` acts as a coefficient for the loss. If a scalar is provided, then
the loss is simply scaled by the given value. If `weights` is a `Tensor` of
shape `[batch_size]`, then the total loss for each sample of the batch is
rescaled by the corresponding element in the `weights` vector. If the shape of
`weights` matches the shape of `predictions`, then the loss of each
measurable element of `predictions` is scaled by the corresponding value of
`weights`.
Args:
weights: Optional `Tensor` whose rank is either 0, or the same rank as
`labels`, and must be broadcastable to `labels` (i.e., all dimensions must
be either `1`, or the same as the corresponding `losses` dimension).
name: operation name.
scope: operation scope.
collect: whether to collect this metric under the metric collection.
Returns:
A scalar `Tensor` representing the loss value.
"""
def inner_loss(y_true, y_pred):
losses = math_ops.abs(math_ops.subtract(y_pred, y_true))
return losses
return built_loss(inner_loss, weights, name, scope, collect)
评论列表
文章目录