How exactly does Keras calculate the validation accuracy?

After each epoch, Keras provides the following evaluations (depending on how the model is compiled):

1. train_accuracy
2. train_loss
3. validation_loss
4. validation_accuracy

Keras evaluates the performance of the model using the validation set at the end of each epoch. But how does Keras do this? Assume that we are performing binary classification and using a binary loss function. Assume that there are 100 images in the validation set.

QUESTION: Can the accuracy can be found by simply calculating accuracy for each item and then average them (/100)?

CONTEXT: I want to implement a custom loss function that calculates the loss towards reducing validation loss (increasing validation accuracy). Therefore, I need to understand how the accuracy is calculated for the validation set.

• Keras is a powerful tool that does many things. Some more automated than others. It would be best to read and understand the code, referring to the documentation if necessary (I presume you're using someone else's code?). In any case, we would need more information about what functions are being used before we can tell. Aug 16, 2022 at 9:25
• From what I understand, the reason for your question is that are trying to calculate a loss from the validation set. Please note that if you were to do such a thing, that is no longer a validation set, but a second train set. A validation set is specifically used to monitor the performance without learning from that set of data. Nov 8, 2022 at 8:03

$$Accuracy\ =\ \frac{Concordant\ samples}{Total\ samples}$$
Assume we have a binary classification task and 5 validation samples. If y_pred = [0, 1, 1, 0, 1] and y_val = [0, 1, 1, 1, 0], then there are 3 concordant samples, giving an accuracy of 3/5 = 60%.