Abhishek Bhatia
Abhishek Bhatia

Reputation: 9806

Keras cross entropy loss

How can I compute cross-entropy in keras? I compute L1 loss as follows:

def l1_loss(y_true, y_pred):
    return K.sum(K.abs(y_pred - y_true), axis=-1)

Upvotes: 2

Views: 5593

Answers (1)

maz
maz

Reputation: 1980

from https://keras.io/backend/

K.categorical_crossentropy(y_pred, y_true)

categorical_crossentropy

categorical_crossentropy(output, target, from_logits=False)

Categorical crossentropy between an output tensor and a target tensor.

Arguments:

  • output: A tensor resulting from a softmax (unless from_logits is True, in which case output is expected to be the logits).

  • target: A tensor of the same shape as output.

  • from_logits: Boolean, whether output is the result of a softmax, or is a tensor of logits.

Upvotes: 5

Related Questions