Package ai.djl.metric
Class Metrics
- java.lang.Object
-
- ai.djl.metric.Metrics
-
public class Metrics extends java.lang.ObjectA collection ofMetricobjects organized by metric name.Metricis a utility class that is used in theTrainerandPredictorto capture performance and other metrics during runtime.It is built as a collection of individual
Metricclasses. As a container for individual metrics classes,Metricsstores 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 emptyMetricsinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMetric(Metric metric)Adds aMetricto the collection.voidaddMetric(java.lang.String name, java.lang.Number value)Adds aMetricgiven the metric'snameandvalue.voidaddMetric(java.lang.String name, java.lang.Number value, Unit unit)Adds aMetricgiven the metric'sname,value, andunit.java.util.List<Metric>getMetric(java.lang.String name)Returns allMetrics with the specified metric name.java.util.Set<java.lang.String>getMetricNames()Returns a set ofStringmetric names.booleanhasMetric(java.lang.String name)Returnstrueif the metrics object has a metric with the given name.MetriclatestMetric(java.lang.String name)Returns the latestMetricwith the specified metric name.doublemean(java.lang.String metricName)Returns the average value of the specified metric.Metricpercentile(java.lang.String metricName, int percentile)Returns a percentileMetricobject for the specified metric name.voidsetLimit(int limit)Sets the max size for each metric.voidsetOnLimit(java.util.function.BiConsumer<Metrics,java.lang.String> onLimit)Sets the callback function when hit the limit.
-
-
-
Method Detail
-
setLimit
public void setLimit(int limit)
Sets the max size for each metric.- Parameters:
limit- the max size for each metric
-
setOnLimit
public void setOnLimit(java.util.function.BiConsumer<Metrics,java.lang.String> onLimit)
Sets the callback function when hit the limit.- Parameters:
onLimit- the callback function
-
addMetric
public void addMetric(Metric metric)
Adds aMetricto the collection.- Parameters:
metric- theMetricto be added
-
addMetric
public void addMetric(java.lang.String name, java.lang.Number value)Adds aMetricgiven the metric'snameandvalue.- Parameters:
name- the metric namevalue- the metric value
-
addMetric
public void addMetric(java.lang.String name, java.lang.Number value, Unit unit)Adds aMetricgiven the metric'sname,value, andunit.- Parameters:
name- the metric namevalue- the metric valueunit- the metric unit
-
hasMetric
public boolean hasMetric(java.lang.String name)
Returnstrueif the metrics object has a metric with the given name.- Parameters:
name- the name to check for- Returns:
trueif the metrics object has a metric with the given name
-
getMetric
public java.util.List<Metric> getMetric(java.lang.String name)
Returns allMetrics with the specified metric name.- Parameters:
name- the name of the metric- Returns:
- a list of
Metricwith the specified metric name
-
getMetricNames
public java.util.Set<java.lang.String> getMetricNames()
Returns a set ofStringmetric names.- Returns:
- a set of
Stringmetric names
-
latestMetric
public Metric latestMetric(java.lang.String name)
Returns the latestMetricwith the specified metric name.- Parameters:
name- the name of the metric- Returns:
- the
Metricwith 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 percentileMetricobject for the specified metric name.- Parameters:
metricName- the name of the metricpercentile- the percentile- Returns:
- the
Metricobject at specifiedpercentile
-
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
-
-