【问题标题】:compute loss between to matrices计算矩阵之间的损失
【发布时间】:2020-07-19 11:33:28
【问题描述】:

在 google 的一篇文章 (EXPLORING TRADEOFFS IN MODELS FOR LOW-LATENCY SPEECH ENHANCEMENT) 中使用这个

损失函数来最小化错误,我已经用Tensorflow在Python中编写了这个函数,

def loss_cal(noise_source, mask, target):
    landa = 0.113
    masked_spec = noise_source*mask
    cc = K.l2_normalize(tf.abs(tf.pow(tf.maximum(1e-4, target), 0.3))-tf.abs(tf.pow(tf.maximum(1e-4, masked_spec), 0.3)))
    cm = K.l2_normalize(tf.math.pow(tf.maximum(1e-4, target), 0.3)-tf.math.pow(tf.maximum(1e-4, masked_spec), 0.3))
    res = tf.math.square(cc)+landa*tf.math.square(cm)
    return res

但它返回一个矩阵,而损失函数必须重新计算一个比例,请纠正我,我的实现是否错误?或者可以训练一个损失为矩阵的模型?

【问题讨论】:

    标签: python-3.x machine-learning deep-learning tensorflow2.0 loss-function


    【解决方案1】:

    您不应该只使用norm,而不是l2_normalize吗?

    l2_normalize 返回一个用范数归一化的矩阵。

    【讨论】:

    • 但在文章中使用了l2_normalize
    • @WalidBousseta 在公式中他们使用 2 范数(欧几里得范数),这是 tf.norm 的默认值。它是一个标量。 l2_normalize 使用 2 范数对矩阵进行归一化。
    猜你喜欢
    • 2017-11-03
    • 1970-01-01
    • 2020-03-13
    • 2018-12-02
    • 2016-11-29
    • 1970-01-01
    • 2020-05-19
    • 2011-02-28
    • 1970-01-01
    相关资源
    最近更新 更多