def hinge_loss(weights=1.0, name='HingeLoss', scope=None, collect=True):
"""Hinge Loss.
Args:
weights: Coefficients for the loss a `scalar`.
name: name of the op.
scope: The scope for the operations performed in computing the loss.
collect: add to losses collection.
Returns:
A scalar `Tensor` representing the loss value.
Raises:
ValueError: If `predictions` shape doesn't match `labels` shape, or `weights` is `None`.
"""
def inner_loss(y_true, y_pred):
all_ones = array_ops.ones_like(y_true)
y_true = math_ops.subtract(2 * y_true, all_ones)
losses = tf.nn.relu(math_ops.subtract(all_ones, math_ops.multiply(y_true, y_pred)))
return losses
return built_loss(inner_loss, weights, name, scope, collect)
评论列表
文章目录