Package ai.djl.metric
Class Metrics
- java.lang.Object
-
- ai.djl.metric.Metrics
-
public class Metrics extends java.lang.Object
A collection ofMetric
objects organized by metric name.Metric
is a utility class that is used in theTrainer
andPredictor
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 emptyMetrics
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMetric(Metric metric)
Adds aMetric
to the collection.void
addMetric(java.lang.String name, java.lang.Number value)
Adds aMetric
given the metric'sname
andvalue
.void
addMetric(java.lang.String name, java.lang.Number value, Unit unit)
Adds aMetric
given the metric'sname
,value
, andunit
.java.util.List<Metric>
getMetric(java.lang.String name)
Returns allMetric
s with the specified metric name.java.util.Set<java.lang.String>
getMetricNames()
Returns a set ofString
metric names.boolean
hasMetric(java.lang.String name)
Returnstrue
if the metrics object has a metric with the given name.Metric
latestMetric(java.lang.String name)
Returns the latestMetric
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 percentileMetric
object for the specified metric name.
-
-
-
Method Detail
-
addMetric
public void addMetric(Metric metric)
Adds aMetric
to the collection.- Parameters:
metric
- theMetric
to be added
-
addMetric
public void addMetric(java.lang.String name, java.lang.Number value)
Adds aMetric
given the metric'sname
andvalue
.- Parameters:
name
- the metric namevalue
- the metric value
-
addMetric
public void addMetric(java.lang.String name, java.lang.Number value, Unit unit)
Adds aMetric
given the metric'sname
,value
, andunit
.- Parameters:
name
- the metric namevalue
- the metric valueunit
- the metric unit
-
hasMetric
public boolean hasMetric(java.lang.String name)
Returnstrue
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 allMetric
s 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 ofString
metric names.- Returns:
- a set of
String
metric names
-
latestMetric
public Metric latestMetric(java.lang.String name)
Returns the latestMetric
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 percentileMetric
object for the specified metric name.- Parameters:
metricName
- the name of the metricpercentile
- the percentile- Returns:
- the
Metric
object 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
-
-