'binary_crossentropy' & 'categorical_crossentropy' in keras
In model.compile(*)
of keras, I met binary_crossentropy
& categorical_crossentropy
. These two kinds of loss somehow made me confused.
Checking their underlying will reveal the mechanism of these two kinds of loss.
loss | refer to |
---|---|
binary_crossentropy | K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1) |
categorical_crossentropy | tf.nn.softmax_cross_entropy_with_logits(labels=target, logits=output) |
The problem is what is binary_crossentropy
and softmax_cross_entropy_with_logits
in TensorFlow
.
binary_crossentropy
(andtf.nn.sigmoid_cross_entropy_with_logits
under the hood) is for binary multi-label classification (labels are independent).
categorical_crossentropy
(andtf.nn.softmax_cross_entropy_with_logits
under the hood) is for multi-class classification (classes are exclusive).
ref:
python - Keras: binary_crossentropy & categorical_crossentropy confusion - Stack Overflow
https://stackoverflow.com/questions/47877083/keras-binary-crossentropy-categorical-crossentropy-confusion