hedwig100 / ranzcr

ranzcr
0 stars 0 forks source link

Weighted Lossを用いてTrainingする #1

Closed hedwig100 closed 3 years ago

hedwig100 commented 3 years ago

多次元の出力にclass_weightを適用する方法を調べる.

hedwig100 commented 3 years ago

これでできているはず

def WeightedBinaryCrossentropy(y_true,y_pred):
    y_true = tf.cast(y_true,tf.float32)
    pos_loss = -mul(mul(      y_true,tf.math.log(    y_pred)),pos_weight) 
    neg_loss = -mul(mul(1.0 - y_true,tf.math.log(1 - y_pred)),neg_weight) 
    loss = tf.add(pos_loss,neg_loss)
    return tf.math.reduce_mean(loss,0)