Class Metrics

java.lang.Object
org.tensorflow.framework.metrics.Metrics

public class Metrics extends Object
Static methods for computing metrics.
  • Constructor Details

    • Metrics

      public Metrics()
  • Method Details

    • topKCategoricalAccuracy

      public static <T extends TNumber> Operand<T> topKCategoricalAccuracy(Ops tf, Operand<? extends TNumber> labels, Operand<T> predictions, long k)
      Computes how often targets are in the top K predictions.

      Standalone usage:

          Operand<TInt32> labels = tf.constant(new int[][]
                                         {{0, 0, 1}, {0, 1, 0}});
          Operand<TFloat32> predictions = tf.constant(new float[][]
                                         {{0.1f, 0.9f, 0.8f}, {0.05f, 0.95f, 0f}});
          Operand<TFloat32> m = Metrics.topKCategoricalAccuracy(
                                         labels, predictions, 3)
          //m.shape().toString == "[2]"
      
      Type Parameters:
      T - the data type for the predictions and results
      Parameters:
      tf - the TensorFlow Ops encapsulating a Graph environment..
      labels - the ground truth values.
      predictions - The prediction values.
      k - Number of top elements to look at for computing accuracy.
      Returns:
      the Operand for the Top K categorical accuracy value.
      Throws:
      IllegalArgumentException - if the TensorFlow Ops scope does not encapsulate a Graph environment.
    • sparseTopKCategoricalAccuracy

      public static <T extends TNumber, U extends TNumber> Operand<T> sparseTopKCategoricalAccuracy(Ops tf, Operand<U> labels, Operand<T> predictions, int k)
      Computes how often integer targets are in the top K predictions.

      Standalone usage:

          Operand<TInt32> labels = tf.constant(new int[]{2, 1});
          Operand<TFloat32> predictions = tf.constant(new float[][]
                                 {{0.1f, 0.9f, 0.f8}, {0.05f, 0.95f, 0f}});
          Operand<TFloat32> m = Metrics.topKCategoricalAccuracy(
                                         labels, predictions, 3)
          //m.shape().toString == "[2]"
      
      Type Parameters:
      T - the data type for the predictions and results
      U - the data type ofr the labels.
      Parameters:
      tf - the TensorFlow Ops encapsulating a Graph environment..
      labels - the ground truth values.
      predictions - The prediction values.
      k - Number of top elements to look at for computing accuracy.
      Returns:
      the Operand for the Sparse top K categorical accuracy value.
      Throws:
      IllegalArgumentException - if the TensorFlow Ops scope does not encapsulate a Graph environment.