Package ai.djl.modality
Class Classifications
- java.lang.Object
-
- ai.djl.modality.Classifications
-
- All Implemented Interfaces:
BytesSupplier,Ensembleable<Classifications>,ai.djl.util.JsonSerializable,java.io.Serializable
- Direct Known Subclasses:
DetectedObjects
public class Classifications extends java.lang.Object implements ai.djl.util.JsonSerializable, Ensembleable<Classifications>
Classificationsis the container that stores the classification results for classification on a single input.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClassifications.ClassificationAClassificationstores the classification result for a single class on a single input.static classClassifications.ClassificationsSerializerA customized Gson serializer to serialize theClassificationsobject.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.String>classNamesprotected java.util.List<java.lang.Double>probabilities
-
Constructor Summary
Constructors Constructor Description Classifications(java.util.List<java.lang.String> classNames, NDArray probabilities)Constructs aClassificationsusing list of classNames parallel to an NDArray of probabilities.Classifications(java.util.List<java.lang.String> classNames, NDArray probabilities, int topK)Constructs aClassificationsusing list of classNames parallel to an NDArray of probabilities.Classifications(java.util.List<java.lang.String> classNames, java.util.List<java.lang.Double> probabilities)Constructs aClassificationsusing a parallel list of classNames and probabilities.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Classifications.Classification>
Tbest()Returns the most likely class for the classification.ClassificationsensembleWith(java.util.Iterator<Classifications> it)Creates an ensembled output with a list of outputs.<T extends Classifications.Classification>
Tget(java.lang.String className)Returns the result for a particular class name.java.lang.StringgetAsString()Returns theStringpresentation of the object.java.util.List<java.lang.String>getClassNames()Returns the classes that were classified into.java.util.List<java.lang.Double>getProbabilities()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>
java.util.List<T>items()Returns a classification item for each potential class for the input.voidsetTopK(int topK)Set the topK number of classes to be displayed.java.nio.ByteBuffertoByteBuffer()Returns theByteBufferpresentation of the object.java.lang.StringtoJson()<T extends Classifications.Classification>
java.util.List<T>topK()Returns a list of the top classes.<T extends Classifications.Classification>
java.util.List<T>topK(int k)Returns a list of the topkbest classes.java.lang.StringtoString()-
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
-
-
-
-
Constructor Detail
-
Classifications
public Classifications(java.util.List<java.lang.String> classNames, java.util.List<java.lang.Double> probabilities)Constructs aClassificationsusing a parallel list of classNames and probabilities.- Parameters:
classNames- the names of the classesprobabilities- the probabilities for each class for the input
-
Classifications
public Classifications(java.util.List<java.lang.String> classNames, NDArray probabilities)Constructs aClassificationsusing 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
public Classifications(java.util.List<java.lang.String> classNames, NDArray probabilities, int topK)Constructs aClassificationsusing 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 Detail
-
getClassNames
public java.util.List<java.lang.String> getClassNames()
Returns the classes that were classified into.- Returns:
- the classes that were classified into
-
getProbabilities
public java.util.List<java.lang.Double> 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
public <T extends Classifications.Classification> java.util.List<T> 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
public <T extends Classifications.Classification> T item(int index)
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
public <T extends Classifications.Classification> java.util.List<T> 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
public <T extends Classifications.Classification> java.util.List<T> topK(int k)
Returns a list of the topkbest 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
public <T extends Classifications.Classification> T 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
public <T extends Classifications.Classification> T get(java.lang.String className)
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
public java.lang.String toJson()
- Specified by:
toJsonin interfaceai.djl.util.JsonSerializable
-
getAsString
public java.lang.String getAsString()
Returns theStringpresentation of the object.- Specified by:
getAsStringin interfaceBytesSupplier- Returns:
- the
Stringpresentation of the object
-
toByteBuffer
public java.nio.ByteBuffer toByteBuffer()
Returns theByteBufferpresentation of the object.- Specified by:
toByteBufferin interfaceBytesSupplier- Returns:
- the
ByteBufferpresentation of the object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
ensembleWith
public Classifications ensembleWith(java.util.Iterator<Classifications> it)
Creates an ensembled output with a list of outputs.- Specified by:
ensembleWithin interfaceEnsembleable<Classifications>- Parameters:
it- the outputs to ensemble with. It uses the caller class to determine how to ensemble.- Returns:
- the ensembled (averaged) output
-
-