public class TopKAccuracy extends AbstractAccuracy
TopKAccuracy
is an Evaluator
that computes the accuracy of the top k predictions.
TopKAccuracy
differs from AbstractAccuracy
in that it considers the prediction
to be `True` as long as the ground truth label is in the top K predicated labels. If `top_k = 1`,
then TopKAccuracy
is identical to Accuracy
.
axis, correctInstances, index
totalInstances
Constructor and Description |
---|
TopKAccuracy(int topK)
Creates an instance of
TopKAccuracy evaluator that computes topK accuracy across axis
1 along the 0th index. |
TopKAccuracy(int index,
int topK)
Creates an instance of
TopKAccuracy evaluator that computes topK accuracy across axis
1 along the given index. |
TopKAccuracy(java.lang.String name,
int index,
int topK)
Creates a
TopKAccuracy instance. |
Modifier and Type | Method and Description |
---|---|
protected ai.djl.util.Pair<java.lang.Long,NDArray> |
accuracyHelper(NDList labels,
NDList predictions)
A helper for classes extending
AbstractAccuracy . |
addAccumulator, evaluate, getAccumulator, resetAccumulator, updateAccumulator
checkLabelShapes, checkLabelShapes, getName
public TopKAccuracy(java.lang.String name, int index, int topK)
TopKAccuracy
instance.name
- the accuracy name, default "Top_K_Accuracy"index
- the index of the NDArray
in labels to compute topK accuracy fortopK
- the value of Kpublic TopKAccuracy(int index, int topK)
TopKAccuracy
evaluator that computes topK accuracy across axis
1 along the given index.index
- the index of the NDArray
in labels to compute topK accuracy fortopK
- the value of Kpublic TopKAccuracy(int topK)
TopKAccuracy
evaluator that computes topK accuracy across axis
1 along the 0th index.topK
- the value of Kprotected ai.djl.util.Pair<java.lang.Long,NDArray> accuracyHelper(NDList labels, NDList predictions)
AbstractAccuracy
AbstractAccuracy
.accuracyHelper
in class AbstractAccuracy
labels
- the labels to get accuracy forpredictions
- the predictions to get accuracy for