'How to get precision and recall for multiclass image classification

I built an image classification model and I want to get precision and recall but I don't know how to get it. here is my code and error model error



Solution 1:[1]

Usually it can be done like this:

model.compile(... , metrics=[tf.keras.metrics.Recall(), tf.keras.metrics.Precision()])

UPD Also you can try use this package https://pypi.org/project/keras-metrics/

import keras_metrics
model.compile(optimizer='adam',
          loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
          metrics=['accuracy', keras_metrics.precision(), keras_metrics.recall() ])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1