Package ai.djl.modality
Class Classifications
java.lang.Object
ai.djl.modality.Classifications
- All Implemented Interfaces:
BytesSupplier
,Ensembleable<Classifications>
,ai.djl.util.JsonSerializable
,Serializable
- Direct Known Subclasses:
DetectedObjects
public class Classifications
extends Object
implements ai.djl.util.JsonSerializable, Ensembleable<Classifications>
Classifications
is the container that stores the classification results for
classification on a single input.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AClassification
stores the classification result for a single class on a single input.static final class
A customized Gson serializer to serialize theClassifications
object. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
-
Constructor Summary
ConstructorsConstructorDescriptionClassifications
(List<String> classNames, NDArray probabilities) Constructs aClassifications
using list of classNames parallel to an NDArray of probabilities.Classifications
(List<String> classNames, NDArray probabilities, int topK) Constructs aClassifications
using list of classNames parallel to an NDArray of probabilities.Classifications
(List<String> classNames, List<Double> probabilities) Constructs aClassifications
using a parallel list of classNames and probabilities. -
Method Summary
Modifier and TypeMethodDescription<T extends Classifications.Classification>
Tbest()
Returns the most likely class for the classification.Creates an ensembled output with a list of outputs.<T extends Classifications.Classification>
TReturns the result for a particular class name.Returns theString
presentation of the object.Returns the classes that were classified into.Returns the list of probabilities for each class (matching the order of the class names).<T extends Classifications.Classification>
Titem
(int index) Returns the item at a given index based on the order used to construct theClassifications
.<T extends Classifications.Classification>
List<T>items()
Returns a classification item for each potential class for the input.final void
setTopK
(int topK) Set the topK number of classes to be displayed.Returns theByteBuffer
presentation of the object.toJson()
<T extends Classifications.Classification>
List<T>topK()
Returns a list of the top classes.<T extends Classifications.Classification>
List<T>topK
(int k) Returns a list of the topk
best classes.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ai.djl.ndarray.BytesSupplier
getAsBytes, getAsObject
-
Field Details
-
classNames
-
probabilities
-
topK
protected int topK
-
-
Constructor Details
-
Classifications
Constructs aClassifications
using a parallel list of classNames and probabilities.- Parameters:
classNames
- the names of the classesprobabilities
- the probabilities for each class for the input
-
Classifications
Constructs aClassifications
using list of classNames parallel to an NDArray of probabilities.- Parameters:
classNames
- the names of the classesprobabilities
- the probabilities for each class for the input
-
Classifications
Constructs aClassifications
using list of classNames parallel to an NDArray of probabilities.- Parameters:
classNames
- the names of the classesprobabilities
- the probabilities for each class for the inputtopK
- the number of top classes to return
-
-
Method Details
-
getClassNames
Returns the classes that were classified into.- Returns:
- the classes that were classified into
-
getProbabilities
Returns the list of probabilities for each class (matching the order of the class names).- Returns:
- the list of probabilities for each class (matching the order of the class names)
-
setTopK
public final void setTopK(int topK) Set the topK number of classes to be displayed.- Parameters:
topK
- the number of top classes to return
-
items
Returns a classification item for each potential class for the input.- Type Parameters:
T
- the type of classification item for the task- Returns:
- the list of classification items
-
item
Returns the item at a given index based on the order used to construct theClassifications
.- Type Parameters:
T
- the type of classification item for the task- Parameters:
index
- the index of the item to return- Returns:
- the item at the given index, equivalent to
classifications.items().get(index)
-
topK
Returns a list of the top classes.- Type Parameters:
T
- the type of the classification item for the task- Returns:
- the list of classification items for the best classes in order of best to worst
-
topK
Returns a list of the topk
best classes.- Type Parameters:
T
- the type of the classification item for the task- Parameters:
k
- the number of classes to return- Returns:
- the list of classification items for the best classes in order of best to worst
-
best
Returns the most likely class for the classification.- Type Parameters:
T
- the type of the classification item for the task- Returns:
- the classification item
-
get
Returns the result for a particular class name.- Type Parameters:
T
- the type of the classification item for the task- Parameters:
className
- the class name to get results for- Returns:
- the (first if multiple) classification item
-
toJson
- Specified by:
toJson
in interfaceai.djl.util.JsonSerializable
-
getAsString
Returns theString
presentation of the object.- Specified by:
getAsString
in interfaceBytesSupplier
- Returns:
- the
String
presentation of the object
-
toByteBuffer
Returns theByteBuffer
presentation of the object.- Specified by:
toByteBuffer
in interfaceBytesSupplier
- Returns:
- the
ByteBuffer
presentation of the object
-
toString
-
ensembleWith
Creates an ensembled output with a list of outputs.- Specified by:
ensembleWith
in interfaceEnsembleable<Classifications>
- Parameters:
it
- the outputs to ensemble with. It uses the caller class to determine how to ensemble.- Returns:
- the ensembled (averaged) output
-