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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds aMetricto the collection.voidAdds aMetricgiven the metric'snameandvalue.voidAdds aMetricgiven the metric'sname,value, andunit.Returns allMetrics with the specified metric name.Returns a set ofStringmetric names.booleanReturnstrueif the metrics object has a metric with the given name.latestMetric(String name) Returns the latestMetricwith the specified metric name.doubleReturns the average value of the specified metric.percentile(String metricName, int percentile) Returns a percentileMetricobject for the specified metric name.voidsetLimit(int limit) Sets the max size for each metric.voidsetOnLimit(BiConsumer<Metrics, String> onLimit) Sets the callback function when hit the limit.
-
Constructor Details
-
Metrics
public Metrics()Constructs an emptyMetricsinstance.
-
-
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 aMetricto the collection.- Parameters:
metric- theMetricto be added
-
addMetric
Adds aMetricgiven the metric'snameandvalue.- Parameters:
name- the metric namevalue- the metric value
-
addMetric
Adds aMetricgiven the metric'sname,value, andunit.- Parameters:
name- the metric namevalue- the metric valueunit- the metric unitdimensions- the metric dimensions
-
hasMetric
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
Returns allMetrics with the specified metric name.- Parameters:
name- the name of the metric- Returns:
- a list of
Metricwith the specified metric name
-
getMetricNames
Returns a set ofStringmetric names.- Returns:
- a set of
Stringmetric names
-
latestMetric
Returns the latestMetricwith the specified metric name.- Parameters:
name- the name of the metric- Returns:
- the
Metricwith the specified metric name - Throws:
IllegalArgumentException- if the given name is not found
-
percentile
Returns a percentileMetricobject for the specified metric name.- Parameters:
metricName- the name of the metricpercentile- the percentile- Returns:
- the
Metricobject 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
-