Class TopKAccuracy


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.

  • Constructor Details

    • TopKAccuracy

      public TopKAccuracy(String name, int topK)
      Creates a TopKAccuracy instance.
      Parameters:
      name - the accuracy name, default "Top_K_Accuracy"
      topK - the value of K
    • TopKAccuracy

      public TopKAccuracy(int topK)
      Creates an instance of TopKAccuracy evaluator that computes topK accuracy across axis 1 along the 0th index.
      Parameters:
      topK - the value of K
  • Method Details

    • accuracyHelper

      protected ai.djl.util.Pair<Long,NDArray> accuracyHelper(NDList labels, NDList predictions)
      A helper for classes extending AbstractAccuracy.
      Specified by:
      accuracyHelper in class AbstractAccuracy
      Parameters:
      labels - the labels to get accuracy for
      predictions - the predictions to get accuracy for
      Returns:
      a pair(number of total values, ndarray int of correct values)