Class Classifications

  • All Implemented Interfaces:
    BytesSupplier, ai.djl.util.JsonSerializable, java.io.Serializable
    Direct Known Subclasses:
    DetectedObjects

    public class Classifications
    extends java.lang.Object
    implements ai.djl.util.JsonSerializable
    Classifications is the container that stores the classification results for classification on a single input.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<java.lang.String> classNames  
      protected java.util.List<java.lang.Double> probabilities  
    • Constructor Summary

      Constructors 
      Constructor Description
      Classifications​(java.util.List<java.lang.String> classNames, NDArray probabilities)
      Constructs a Classifications using list of classNames parallel to an NDArray of probabilities.
      Classifications​(java.util.List<java.lang.String> classNames, NDArray probabilities, int topK)
      Constructs a Classifications using 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 a Classifications using a parallel list of classNames and probabilities.
    • Field Detail

      • classNames

        protected java.util.List<java.lang.String> classNames
      • probabilities

        protected java.util.List<java.lang.Double> probabilities
    • Constructor Detail

      • Classifications

        public Classifications​(java.util.List<java.lang.String> classNames,
                               java.util.List<java.lang.Double> probabilities)
        Constructs a Classifications using a parallel list of classNames and probabilities.
        Parameters:
        classNames - the names of the classes
        probabilities - the probabilities for each class for the input
      • Classifications

        public Classifications​(java.util.List<java.lang.String> classNames,
                               NDArray probabilities)
        Constructs a Classifications using list of classNames parallel to an NDArray of probabilities.
        Parameters:
        classNames - the names of the classes
        probabilities - the probabilities for each class for the input
      • Classifications

        public Classifications​(java.util.List<java.lang.String> classNames,
                               NDArray probabilities,
                               int topK)
        Constructs a Classifications using list of classNames parallel to an NDArray of probabilities.
        Parameters:
        classNames - the names of the classes
        probabilities - the probabilities for each class for the input
        topK - the number of top classes to return
    • Method Detail

      • 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 the Classifications.
        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 top k 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

        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:
        toJson in interface ai.djl.util.JsonSerializable
      • getAsString

        public java.lang.String getAsString()
        Returns the String presentation of the object.
        Specified by:
        getAsString in interface BytesSupplier
        Returns:
        the String presentation of the object
      • toByteBuffer

        public java.nio.ByteBuffer toByteBuffer()
        Returns the ByteBuffer presentation of the object.
        Specified by:
        toByteBuffer in interface BytesSupplier
        Returns:
        the ByteBuffer presentation of the object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object