2019b3cae62bdb7740e93b0820fb25692c955cd6,src/pytools/metrics.py,weighted_categorical_crossentropy,loss,#weighted_categorical_crossentropy#Any#Any#,69

Before Change


        // scale preds so that the class probas of each sample sum to 1
        y_pred /= K.sum(y_pred, axis=-1, keepdims=True)
        // clip
        y_pred = K.clip(y_pred, K.epsilon(), 1)
        // calc        
        p = y_true*K.log(y_pred)
        loss = p*self.weights
        loss =-K.sum(loss,-1)
//         return loss
        return K.mean(loss)

// def nonzero_acc(y_true, y_pred):
//     lab_true = K.argmax(y_true, axis=-1)
//     lab_pred = K.argmax(y_pred, axis=-1)

After Change


        """ prepare a loss of the given metric/loss operating on non-bg data """
        yt = y_true.eval()
        ytbg = np.where(yt == 0)
        y_true_fix = K.variable(yt.flat(ytbg))
        y_pred_fix = K.variable(y_pred.eval().flat(ytbg))
        return self.metric(y_true_fix, y_pred_fix)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 7

Instances


Project Name: adalca/neuron
Commit Name: 2019b3cae62bdb7740e93b0820fb25692c955cd6
Time: 2017-03-16
Author: adalca@mit.edu
File Name: src/pytools/metrics.py
Class Name: weighted_categorical_crossentropy
Method Name: loss


Project Name: XifengGuo/CapsNet-Keras
Commit Name: 0ca571cb6c0fb465befebcb4e1fccef6efaecda3
Time: 2017-11-24
Author: guoxifeng1990@163.com
File Name: capsulelayers.py
Class Name: Mask
Method Name: call


Project Name: adalca/neuron
Commit Name: 9bcf05406490ca72b698db24636e5f2a51a5c82a
Time: 2017-06-14
Author: adalca@sumac.csail.mit.edu
File Name: neuron/metrics.py
Class Name: CategoricalCrossentropy
Method Name: loss