【问题标题】:Differentiable Hamming Loss for TensorFlowTensorFlow 的可微分汉明损失
【发布时间】:2020-02-04 00:15:48
【问题描述】:

汉明损失计算我们的预测错误归一化的标签数量。

HammingLoss 作为度量的标准实现依赖于计算错误预测,大致如下:(在 TF 上)

count_non_zero = tf.math.count_nonzero(actuals - predictions)
return tf.reduce_mean(count_non_zero / actuals.get_shape()[-1])

将汉明损失实现为实际损失需要它是可微的,由于tf.math.count_nonzero 而不是这种情况。 另一种(和近似的)方法是以这种方式计算非零标签,但不幸的是,NN 似乎没有改善。

def hamming_loss(y_true, y_pred):
  y_true = tf.convert_to_tensor(y_true, name="y_true")
  y_pred = tf.convert_to_tensor(y_pred, name="y_pred")

  diff = tf.cast(tf.math.abs(y_true - y_pred), dtype=tf.float32)

  #Counting non-zeros in a differentiable way
  epsilon = K.epsilon()
  nonzero = tf.reduce_mean(tf.math.abs( diff / (tf.math.abs(diff) + epsilon)))

  return tf.reduce_mean(nonzero / K.int_shape(y_pred)[-1])

最后,TensorFlow 的 Hamming Loss 的正确实现是什么?

[.1]https://hal.archives-ouvertes.fr/hal-01044994/document

【问题讨论】:

标签: python tensorflow machine-learning loss-function


【解决方案1】:

您的网络没有收敛,因为:

diff / (tf.math.abs(diff) + epsilon) 

产生一个0 , 1 向量,它可以消除零和一的梯度

【讨论】:

    猜你喜欢
    • 2020-06-21
    • 1970-01-01
    • 2017-06-26
    • 2017-04-06
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2021-07-18
    • 2018-03-25
    相关资源
    最近更新 更多