1

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?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Seena
  • 101
  • 1
  • 8

1 Answers1

1

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:

ClaudiaR
  • 3,108
  • 2
  • 13
  • 27
  • Please, if this solved your problem, remember to accept the answer by toggling the check mark besides it. See [what to do when someone answers](https://stackoverflow.com/help/someone-answers) – ClaudiaR Aug 12 '22 at 14:56