avalanche.evaluation.metrics.TopkAccuracy

class avalanche.evaluation.metrics.TopkAccuracy(top_k)[source]

The Top-k Accuracy metric. This is a standalone metric. It is defined using torchmetrics.functional accuracy with top_k

__init__(top_k)[source]

Creates an instance of the standalone Top-k Accuracy metric.

By default this metric in its initial state will return a value of 0. The metric can be updated by using the update method while the running top-k accuracy can be retrieved using the result method.

Parameters

top_k – integer number to define the value of k.

Methods

__init__(top_k)

Creates an instance of the standalone Top-k Accuracy metric.

reset([task_label])

Resets the metric. :param task_label: if None, reset the entire dictionary. Otherwise, reset the value associated to task_label.

result([task_label])

Retrieves the running top-k accuracy.

update(predicted_y, true_y, task_labels)

Update the running top-k accuracy given the true and predicted labels.