Package ai.djl.metric

Class Metrics


  • public class Metrics
    extends java.lang.Object
    A collection of Metric objects organized by metric name.

    Metric is a utility class that is used in the Trainer and Predictor to capture performance and other metrics during runtime.

    It is built as a collection of individual Metric classes. As a container for individual metrics classes, Metrics stores them as time series data so that metric-vs-timeline analysis can be performed. It also provides convenient statistical methods for getting aggregated information, such as mean and percentile. The metrics is used to store key performance indicators (KPIs) during inference and training runs. These KPIs include various latencies, CPU and GPU memory consumption, losses, etc.

    For more details about using the metrics, see the metrics tutorial.

    • Constructor Summary

      Constructors 
      Constructor Description
      Metrics()
      Constructs an empty Metrics instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMetric​(Metric metric)
      Adds a Metric to the collection.
      void addMetric​(java.lang.String name, java.lang.Number value)
      Adds a Metric given the metric's name and value.
      void addMetric​(java.lang.String name, java.lang.Number value, Unit unit)
      Adds a Metric given the metric's name, value, and unit.
      java.util.List<Metric> getMetric​(java.lang.String name)
      Returns all Metrics with the specified metric name.
      java.util.Set<java.lang.String> getMetricNames()
      Returns a set of String metric names.
      boolean hasMetric​(java.lang.String name)
      Returns true if the metrics object has a metric with the given name.
      Metric latestMetric​(java.lang.String name)
      Returns the latest Metric with the specified metric name.
      double mean​(java.lang.String metricName)
      Returns the average value of the specified metric.
      Metric percentile​(java.lang.String metricName, int percentile)
      Returns a percentile Metric object for the specified metric name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Metrics

        public Metrics()
        Constructs an empty Metrics instance.
    • Method Detail

      • addMetric

        public void addMetric​(Metric metric)
        Adds a Metric to the collection.
        Parameters:
        metric - the Metric to be added
      • addMetric

        public void addMetric​(java.lang.String name,
                              java.lang.Number value)
        Adds a Metric given the metric's name and value.
        Parameters:
        name - the metric name
        value - the metric value
      • addMetric

        public void addMetric​(java.lang.String name,
                              java.lang.Number value,
                              Unit unit)
        Adds a Metric given the metric's name, value, and unit.
        Parameters:
        name - the metric name
        value - the metric value
        unit - the metric unit
      • hasMetric

        public boolean hasMetric​(java.lang.String name)
        Returns true if the metrics object has a metric with the given name.
        Parameters:
        name - the name to check for
        Returns:
        true if the metrics object has a metric with the given name
      • getMetric

        public java.util.List<Metric> getMetric​(java.lang.String name)
        Returns all Metrics with the specified metric name.
        Parameters:
        name - the name of the metric
        Returns:
        a list of Metric with the specified metric name
      • getMetricNames

        public java.util.Set<java.lang.String> getMetricNames()
        Returns a set of String metric names.
        Returns:
        a set of String metric names
      • latestMetric

        public Metric latestMetric​(java.lang.String name)
        Returns the latest Metric with the specified metric name.
        Parameters:
        name - the name of the metric
        Returns:
        the Metric with the specified metric name
        Throws:
        java.lang.IllegalArgumentException - if the given name is not found
      • percentile

        public Metric percentile​(java.lang.String metricName,
                                 int percentile)
        Returns a percentile Metric object for the specified metric name.
        Parameters:
        metricName - the name of the metric
        percentile - the percentile
        Returns:
        the Metric object at specified percentile
      • mean

        public double mean​(java.lang.String metricName)
        Returns the average value of the specified metric.
        Parameters:
        metricName - the name of the metric
        Returns:
        the average value of the specified metric