losses.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:polyaxon 作者: polyaxon 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号