Class Input

java.lang.Object
ai.djl.modality.Input
Direct Known Subclasses:
Output

public class Input extends Object
A class stores the generic input data for inference.
  • Field Details

  • Constructor Details

    • Input

      public Input()
      Constructs a new Input instance.
  • Method Details

    • isCancelled

      public boolean isCancelled()
      Returns true if the input is cancelled.
      Returns:
      true if the input is cancelled.
    • setCancelled

      public void setCancelled(boolean cancelled)
      Sets the cancelled status.
      Parameters:
      cancelled - the cancelled status
    • getProperties

      public Map<String,String> getProperties()
      Returns the properties of the input.
      Returns:
      the properties of the input
    • setProperties

      public void setProperties(Map<String,String> properties)
      Sets the properties of the input.
      Parameters:
      properties - the properties of the input
    • addProperty

      public void addProperty(String key, String value)
      Adds a property to the input.
      Parameters:
      key - key with which the specified value is to be added
      value - value to be added with the specified key
    • getProperty

      public String getProperty(String key, String defaultValue)
      Returns the value to which the specified key is mapped.
      Parameters:
      key - the key whose associated value is to be returned
      defaultValue - the default mapping of the key
      Returns:
      the value to which the specified key is mapped
    • getContent

      public ai.djl.util.PairList<String,BytesSupplier> getContent()
      Returns the content of the input.

      A Input may contains multiple data.

      Returns:
      the content of the input
    • getContentAsBuffers

      public ai.djl.util.PairList<String,ByteBuffer> getContentAsBuffers()
      Returns the content of the input as ByteBuffers.

      A Input may contains multiple data.

      Returns:
      the content of the input as ByteBuffers.
    • setContent

      public void setContent(ai.djl.util.PairList<String,BytesSupplier> content)
      Sets the content of the input.
      Parameters:
      content - the content of the input
    • add

      public void add(byte[] data)
      Appends an item at the end of the input.
      Parameters:
      data - data to be added
    • add

      public void add(String data)
      Appends an item at the end of the input.
      Parameters:
      data - data to be added
    • add

      public void add(BytesSupplier data)
      Appends an item at the end of the input.
      Parameters:
      data - data to be added
    • add

      public void add(String key, byte[] data)
      Adds a key/value pair to the input content.
      Parameters:
      key - key with which the specified data is to be added
      data - data to be added with the specified key
    • add

      public void add(String key, String data)
      Adds a key/value pair to the input content.
      Parameters:
      key - key with which the specified data is to be added
      data - data to be added with the specified key
    • add

      public void add(String key, BytesSupplier data)
      Adds a key/value pair to the input content.
      Parameters:
      key - key with which the specified data is to be added
      data - data to be added with the specified key
    • add

      public void add(int index, String key, BytesSupplier data)
      Inserts the specified element at the specified position in the input.
      Parameters:
      index - the index at which the specified element is to be inserted
      key - key with which the specified data is to be added
      data - data to be added with the specified key
    • getData

      public BytesSupplier getData()
      Returns the default data item.
      Returns:
      the default data item
    • getDataAsNDList

      public NDList getDataAsNDList(NDManager manager)
      Returns the default data as NDList.
      Parameters:
      manager - NDManager used to create this NDArray
      Returns:
      the default data as NDList
    • get

      public BytesSupplier get(String key)
      Returns the element for the first key found in the Input.
      Parameters:
      key - the key of the element to get
      Returns:
      the element for the first key found in the Input
    • get

      public BytesSupplier get(int index)
      Returns the element at the specified position in the Input.
      Parameters:
      index - the index of the element to return
      Returns:
      the element at the specified position in the Input
    • getAsBytes

      public byte[] getAsBytes(String key)
      Returns the value as byte[] for the first key found in the Input.
      Parameters:
      key - the key of the element to get
      Returns:
      the value as byte[] for the first key found in the Input
    • getAsBytes

      public byte[] getAsBytes(int index)
      Returns the value as byte[] at the specified position in the Input.
      Parameters:
      index - the index of the element to return
      Returns:
      the value as byte[] at the specified position in the Input
    • getAsString

      public String getAsString(String key)
      Returns the value as byte[] for the first key found in the Input.
      Parameters:
      key - the key of the element to get
      Returns:
      the value as byte[] for the first key found in the Input
    • getAsString

      public String getAsString(int index)
      Returns the value as byte[] at the specified position in the Input.
      Parameters:
      index - the index of the element to return
      Returns:
      the value as byte[] at the specified position in the Input
    • getAsNDArray

      public NDArray getAsNDArray(NDManager manager, String key)
      Returns the value as NDArray for the first key found in the Input.
      Parameters:
      manager - NDManager used to create this NDArray
      key - the key of the element to get
      Returns:
      the value as NDArray for the first key found in the Input
    • getAsNDArray

      public NDArray getAsNDArray(NDManager manager, int index)
      Returns the value as NDArray at the specified position in the Input.
      Parameters:
      manager - NDManager used to create this NDArray
      index - the index of the element to return
      Returns:
      the value as NDArray at the specified position in the Input
    • getAsNDList

      public NDList getAsNDList(NDManager manager, String key)
      Returns the value as NDList for the first key found in the Input.
      Parameters:
      manager - NDManager used to create this NDArray
      key - the key of the element to get
      Returns:
      the value as NDList for the first key found in the Input
    • getAsNDList

      public NDList getAsNDList(NDManager manager, int index)
      Returns the value as NDList at the specified position in the Input.
      Parameters:
      manager - NDManager used to create this NDArray
      index - the index of the element to return
      Returns:
      the value as NDList at the specified position in the Input
    • encode

      public byte[] encode() throws IOException
      Encodes all data in the input to a binary form.
      Returns:
      the binary encoding
      Throws:
      IOException - if it fails to encode part of the data
    • encodeInputBase

      protected void encodeInputBase(DataOutputStream os) throws IOException
      Throws:
      IOException
    • decode

      public static Input decode(InputStream is) throws IOException
      Decodes the input from encode().
      Parameters:
      is - the data to decode from
      Returns:
      the decoded input
      Throws:
      IOException - if it fails to decode part of the input
    • decodeInputBase

      protected static void decodeInputBase(DataInputStream dis, Input input) throws IOException
      Throws:
      IOException
    • deepEquals

      public boolean deepEquals(Object o)
      Checks for deep equality with another input.
      Parameters:
      o - the other input.
      Returns:
      whether they and all properties, content, and data are equal
    • toString

      public String toString()
      *
      Overrides:
      toString in class Object