peal.training.training_utils.calculate_validation_statistics¶
- peal.training.training_utils.calculate_validation_statistics(model, dataloaders, tracked_keys, base_path, output_size, device, logits_to_prediction, use_confusion_matrix, explainer, max_validation_samples)[source]¶
Compute accuracy / error statistics and explainer outputs on validation data.
For every dataloader the model is evaluated with temperature-scaled softmax (
explainer.explainer_config.temperature), the prediction is mapped to a class withlogits_to_predictionand the explainer is asked to explain the batch towards the target(y_pred + 1) % output_size. Keys of the explainer result that appear intracked_keysare accumulated.- Parameters:
model (
nn.Module) – Classifier producing logits of shape(B, output_size).dataloaders (
listoftorch.utils.data.DataLoader) – Validation loaders; the sample budget is split evenly between them and a trailing batch smaller thanbatch_sizestops the loop.tracked_keys (
listofstr) – Explainer result keys to collect, e.g."x_counterfactual_list"."hint_list"/"idx_list"additionally unpack a list-valuedyinto label, hints and indices.base_path (
str) – Directory handed toexplainer.explain_batchfor its artefacts.output_size (
int) – Number of classes.device (
strortorch.device) – Device the inputs are moved to.logits_to_prediction (
callable) – Maps a confidence tensor to integer predictions.use_confusion_matrix (
bool) – If True and the accuracy is below 1.0, the normalised off-diagonal confusion matrix is returned aserror_matrix; otherwise a uniform off-diagonal matrix is used.explainer (
ExplainerInterface) – Explainer whoseexplain_batchruns inmode="validation".max_validation_samples (
int) – Upper bound on the number of samples over all dataloaders.
- Returns:
tracked_values (
dict) –{key: list}for every key intracked_keys.validation_stats (
dict) –accuracy(float),confidence_score_stats(zero tensor of shape(output_size, output_size), currently a placeholder) anderror_matrix(flattened tensor of lengthoutput_size ** 2that sums to one). Only the last dataloader’s values are returned.