Implementation of Metric Function
In a simple deep learning task, we may only need to compute the loss of the model. But in practice, we may need to compute some other metrics to evaluate the performance of the model. For example, in a classification task, we may need to compute the accuracy of the model.
Essentially, a metric function is a function that takes the output of the model and the expected output, and compute a scalar that represents the performance of the model. The input and output of the metric function are both tensors. Generally, the output of the metric function is a scalar that represents the performance of the model. Those make the metric function similar to the loss function. But there are still some differences.
- The metric function is not used to optimize the model. It's only used to evaluate the performance of the model.
- The metric function is not required to be differentiable.