Package ai.djl.training.evaluator
Class AbstractAccuracy
java.lang.Object
ai.djl.training.evaluator.Evaluator
ai.djl.training.evaluator.AbstractAccuracy
- Direct Known Subclasses:
Accuracy,BinaryAccuracy,Coverage,SingleShotDetectionAccuracy,TopKAccuracy
Accuracy is an Evaluator that computes the accuracy score.
The accuracy score is defined as \(accuracy(y, \hat{y}) = \frac{1}{n}\sum_{i=0}^{n-1}1(\hat{y_i} == y_i)\)
-
Field Summary
FieldsFields inherited from class ai.djl.training.evaluator.Evaluator
totalInstances -
Constructor Summary
ConstructorsConstructorDescriptionAbstractAccuracy(String name) Creates an accuracy evaluator that computes accuracy across axis 1.AbstractAccuracy(String name, int axis) Creates an accuracy evaluator. -
Method Summary
Modifier and TypeMethodDescriptionaccuracyHelper(NDList labels, NDList predictions) A helper for classes extendingAbstractAccuracy.voidaddAccumulator(String key) Adds an accumulator for the results of the evaluation with the given key.Calculates the evaluation between the labels and the predictions.floatgetAccumulator(String key) Returns the accumulated evaluator value.voidresetAccumulator(String key) Resets the evaluator value with the given key.voidupdateAccumulator(String key, NDList labels, NDList predictions) Updates the evaluator with the given key based on aNDListof labels and predictions.voidupdateAccumulators(String[] keys, NDList labels, NDList predictions) Updates the evaluator with the given keys based on aNDListof labels and predictions.Methods inherited from class ai.djl.training.evaluator.Evaluator
checkLabelShapes, checkLabelShapes, getName
-
Field Details
-
correctInstances
-
axis
protected int axis
-
-
Constructor Details
-
AbstractAccuracy
Creates an accuracy evaluator that computes accuracy across axis 1.- Parameters:
name- the name of the evaluator, default is "Accuracy"
-
AbstractAccuracy
Creates an accuracy evaluator.- Parameters:
name- the name of the evaluator, default is "Accuracy"axis- the axis that represent classes in prediction, default 1
-
-
Method Details
-
accuracyHelper
A helper for classes extendingAbstractAccuracy.- Parameters:
labels- the labels to get accuracy forpredictions- the predictions to get accuracy for- Returns:
- a pair(number of total values, ndarray int of correct values)
-
evaluate
Calculates the evaluation between the labels and the predictions. -
addAccumulator
Adds an accumulator for the results of the evaluation with the given key.- Specified by:
addAccumulatorin classEvaluator- Parameters:
key- the key for the new accumulator
-
updateAccumulator
Updates the evaluator with the given key based on aNDListof labels and predictions.This is a synchronized operation. You should only call it at the end of a batch or epoch.
- Specified by:
updateAccumulatorin classEvaluator- Parameters:
key- the key of the accumulator to updatelabels- aNDListof labelspredictions- aNDListof predictions
-
updateAccumulators
Updates the evaluator with the given keys based on aNDListof labels and predictions.This is a synchronized operation. You should only call it at the end of a batch or epoch.
This is an alternative to @{link
Evaluator.updateAccumulator(String, NDList, NDList)} that may be more efficient when updating multiple accumulators at once.- Overrides:
updateAccumulatorsin classEvaluator- Parameters:
keys- the keys of all the accumulators to updatelabels- aNDListof labelspredictions- aNDListof predictions
-
resetAccumulator
Resets the evaluator value with the given key.- Specified by:
resetAccumulatorin classEvaluator- Parameters:
key- the key of the accumulator to reset
-
getAccumulator
Returns the accumulated evaluator value.- Specified by:
getAccumulatorin classEvaluator- Parameters:
key- the key of the accumulator to get- Returns:
- the accumulated value
-