Package ai.djl.metric
Class Metrics
java.lang.Object
ai.djl.metric.Metrics
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds aMetric
to the collection.void
Adds aMetric
given the metric'sname
andvalue
.void
Adds aMetric
given the metric'sname
,value
, andunit
.Returns allMetric
s with the specified metric name.Returns a set ofString
metric names.boolean
Returnstrue
if the metrics object has a metric with the given name.latestMetric
(String name) Returns the latestMetric
with the specified metric name.double
Returns the average value of the specified metric.percentile
(String metricName, int percentile) Returns a percentileMetric
object for the specified metric name.void
setLimit
(int limit) Sets the max size for each metric.void
setOnLimit
(BiConsumer<Metrics, String> onLimit) Sets the callback function when hit the limit.
-
Constructor Details
-
Metrics
public Metrics()Constructs an emptyMetrics
instance.
-
-
Method Details
-
setLimit
public void setLimit(int limit) Sets the max size for each metric.- Parameters:
limit
- the max size for each metric
-
setOnLimit
Sets the callback function when hit the limit.- Parameters:
onLimit
- the callback function
-
addMetric
Adds aMetric
to the collection.- Parameters:
metric
- theMetric
to be added
-
addMetric
Adds aMetric
given the metric'sname
andvalue
.- Parameters:
name
- the metric namevalue
- the metric value
-
addMetric
Adds aMetric
given the metric'sname
,value
, andunit
.- Parameters:
name
- the metric namevalue
- the metric valueunit
- the metric unit
-
hasMetric
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
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
Returns a set ofString
metric names.- Returns:
- a set of
String
metric names
-
latestMetric
Returns the latestMetric
with the specified metric name.- Parameters:
name
- the name of the metric- Returns:
- the
Metric
with the specified metric name - Throws:
IllegalArgumentException
- if the given name is not found
-
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
Returns the average value of the specified metric.- Parameters:
metricName
- the name of the metric- Returns:
- the average value of the specified metric
-