weighted binary crossentropy keras

Solutions on MaxInterview for weighted binary crossentropy keras by the best coders in the world

showing results for - "weighted binary crossentropy keras"
Emily
17 Mar 2016
1one_weight = (1-num_of_ones)/(num_of_ones + num_of_zeros)
2zero_weight = (1-num_of_zeros)/(num_of_ones + num_of_zeros)
3
4def weighted_binary_crossentropy(zero_weight, one_weight):
5
6    def weighted_binary_crossentropy(y_true, y_pred):
7
8        b_ce = K.binary_crossentropy(y_true, y_pred)
9
10        # weighted calc
11        weight_vector = y_true * one_weight + (1 - y_true) * zero_weight
12        weighted_b_ce = weight_vector * b_ce
13
14        return K.mean(weighted_b_ce)
15
16    return weighted_binary_crossentropy