Seena
Seena

Reputation: 131

difference in categorical crossentropy when specified in loss or metrics

What is the difference between tf.keras.losses.CategoricalCrossentropy and tf.keras.metrics.CategoricalCrossentropy?

model.compile(optimizer=Adam(learning_rate=lr), loss= 'categorical_crossentropy', 
metrics=['accuracy','categorical_crossentropy'])

Question:

15/15 [==============================] - 5s 352ms/step - loss: 0.4043 - accuracy: 0.8634 - categorical_crossentropy: 0.4043 - val_loss: 4.7890 - val_accuracy: 0.7509 - val_categorical_crossentropy: 0.9807

At the end of every epoch I find, loss and categorical_crossentropy have the same value which corresponds to training data.

However, i find difference in the values for the validation data i.e val_loss: 4.7890 vs val_categorical_crossentropy: 0.9807.

Note: my model is

enter image description here

Does anyone know if I am discounting anything here?

Upvotes: 1

Views: 325

Answers (1)

ClaudiaR
ClaudiaR

Reputation: 3414

The main distinction really is that one is a loss and one is a metric. The loss is used to optimize and the metric to evaluate a performance aspect of your model.

The difference is that if you are using a kind of regularization, like batch normalization, it affects your loss, but it does not affect the metric.

Have a look at this posts, that maybe can make things clearer for you:

Upvotes: 1

Related Questions