Package ai.djl.modality
Class Input
- java.lang.Object
-
- ai.djl.modality.Input
-
- Direct Known Subclasses:
Output
public class Input extends java.lang.Object
A class stores the generic input data for inference.
-
-
Field Summary
Fields Modifier and Type Field Description protected ai.djl.util.PairList<java.lang.String,BytesSupplier>
content
protected java.util.Map<java.lang.String,java.lang.String>
properties
-
Constructor Summary
Constructors Constructor Description Input()
Constructs a newInput
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(byte[] data)
Appends an item at the end of the input.void
add(int index, java.lang.String key, BytesSupplier data)
Inserts the specified element at the specified position in the input.void
add(BytesSupplier data)
Appends an item at the end of the input.void
add(java.lang.String data)
Appends an item at the end of the input.void
add(java.lang.String key, byte[] data)
Adds a key/value pair to the input content.void
add(java.lang.String key, BytesSupplier data)
Adds a key/value pair to the input content.void
add(java.lang.String key, java.lang.String data)
Adds a key/value pair to the input content.void
addProperty(java.lang.String key, java.lang.String value)
Adds a property to the input.static Input
decode(java.io.InputStream is)
Decodes the input fromencode()
.protected static void
decodeInputBase(java.io.DataInputStream dis, Input input)
boolean
deepEquals(java.lang.Object o)
Checks for deep equality with another input.byte[]
encode()
Encodes all data in the input to a binary form.protected void
encodeInputBase(java.io.DataOutputStream os)
BytesSupplier
get(int index)
Returns the element at the specified position in theInput
.BytesSupplier
get(java.lang.String key)
Returns the element for the first key found in theInput
.byte[]
getAsBytes(int index)
Returns the value asbyte[]
at the specified position in theInput
.byte[]
getAsBytes(java.lang.String key)
Returns the value asbyte[]
for the first key found in theInput
.NDArray
getAsNDArray(NDManager manager, int index)
Returns the value asNDArray
at the specified position in theInput
.NDArray
getAsNDArray(NDManager manager, java.lang.String key)
Returns the value asNDArray
for the first key found in theInput
.NDList
getAsNDList(NDManager manager, int index)
Returns the value asNDList
at the specified position in theInput
.NDList
getAsNDList(NDManager manager, java.lang.String key)
Returns the value asNDList
for the first key found in theInput
.java.lang.String
getAsString(int index)
Returns the value asbyte[]
at the specified position in theInput
.java.lang.String
getAsString(java.lang.String key)
Returns the value asbyte[]
for the first key found in theInput
.ai.djl.util.PairList<java.lang.String,BytesSupplier>
getContent()
Returns the content of the input.ai.djl.util.PairList<java.lang.String,java.nio.ByteBuffer>
getContentAsBuffers()
Returns the content of the input asByteBuffer
s.BytesSupplier
getData()
Returns the default data item.NDList
getDataAsNDList(NDManager manager)
Returns the default data asNDList
.java.util.Map<java.lang.String,java.lang.String>
getProperties()
Returns the properties of the input.java.lang.String
getProperty(java.lang.String key, java.lang.String defaultValue)
Returns the value to which the specified key is mapped.void
setContent(ai.djl.util.PairList<java.lang.String,BytesSupplier> content)
Sets the content of the input.void
setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Sets the properties of the input.java.lang.String
toString()
*
-
-
-
Field Detail
-
properties
protected java.util.Map<java.lang.String,java.lang.String> properties
-
content
protected ai.djl.util.PairList<java.lang.String,BytesSupplier> content
-
-
Method Detail
-
getProperties
public java.util.Map<java.lang.String,java.lang.String> getProperties()
Returns the properties of the input.- Returns:
- the properties of the input
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Sets the properties of the input.- Parameters:
properties
- the properties of the input
-
addProperty
public void addProperty(java.lang.String key, java.lang.String value)
Adds a property to the input.- Parameters:
key
- key with which the specified value is to be addedvalue
- value to be added with the specified key
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
Returns the value to which the specified key is mapped.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping of the key- Returns:
- the value to which the specified key is mapped
-
getContent
public ai.djl.util.PairList<java.lang.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<java.lang.String,java.nio.ByteBuffer> getContentAsBuffers()
Returns the content of the input asByteBuffer
s.A
Input
may contains multiple data.- Returns:
- the content of the input as
ByteBuffer
s.
-
setContent
public void setContent(ai.djl.util.PairList<java.lang.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(java.lang.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(java.lang.String key, byte[] data)
Adds a key/value pair to the input content.- Parameters:
key
- key with which the specified data is to be addeddata
- data to be added with the specified key
-
add
public void add(java.lang.String key, java.lang.String data)
Adds a key/value pair to the input content.- Parameters:
key
- key with which the specified data is to be addeddata
- data to be added with the specified key
-
add
public void add(java.lang.String key, BytesSupplier data)
Adds a key/value pair to the input content.- Parameters:
key
- key with which the specified data is to be addeddata
- data to be added with the specified key
-
add
public void add(int index, java.lang.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 insertedkey
- key with which the specified data is to be addeddata
- 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 asNDList
.- Parameters:
manager
-NDManager
used to create thisNDArray
- Returns:
- the default data as
NDList
-
get
public BytesSupplier get(java.lang.String key)
Returns the element for the first key found in theInput
.- 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 theInput
.- Parameters:
index
- the index of the element to return- Returns:
- the element at the specified position in the
Input
-
getAsBytes
public byte[] getAsBytes(java.lang.String key)
Returns the value asbyte[]
for the first key found in theInput
.- Parameters:
key
- the key of the element to get- Returns:
- the value as
byte[]
for the first key found in theInput
-
getAsBytes
public byte[] getAsBytes(int index)
Returns the value asbyte[]
at the specified position in theInput
.- Parameters:
index
- the index of the element to return- Returns:
- the value as
byte[]
at the specified position in theInput
-
getAsString
public java.lang.String getAsString(java.lang.String key)
Returns the value asbyte[]
for the first key found in theInput
.- Parameters:
key
- the key of the element to get- Returns:
- the value as
byte[]
for the first key found in theInput
-
getAsString
public java.lang.String getAsString(int index)
Returns the value asbyte[]
at the specified position in theInput
.- Parameters:
index
- the index of the element to return- Returns:
- the value as
byte[]
at the specified position in theInput
-
getAsNDArray
public NDArray getAsNDArray(NDManager manager, java.lang.String key)
Returns the value asNDArray
for the first key found in theInput
.- Parameters:
manager
-NDManager
used to create thisNDArray
key
- the key of the element to get- Returns:
- the value as
NDArray
for the first key found in theInput
-
getAsNDArray
public NDArray getAsNDArray(NDManager manager, int index)
Returns the value asNDArray
at the specified position in theInput
.- Parameters:
manager
-NDManager
used to create thisNDArray
index
- the index of the element to return- Returns:
- the value as
NDArray
at the specified position in theInput
-
getAsNDList
public NDList getAsNDList(NDManager manager, java.lang.String key)
Returns the value asNDList
for the first key found in theInput
.- Parameters:
manager
-NDManager
used to create thisNDArray
key
- the key of the element to get- Returns:
- the value as
NDList
for the first key found in theInput
-
getAsNDList
public NDList getAsNDList(NDManager manager, int index)
Returns the value asNDList
at the specified position in theInput
.- Parameters:
manager
-NDManager
used to create thisNDArray
index
- the index of the element to return- Returns:
- the value as
NDList
at the specified position in theInput
-
encode
public byte[] encode() throws java.io.IOException
Encodes all data in the input to a binary form.- Returns:
- the binary encoding
- Throws:
java.io.IOException
- if it fails to encode part of the data
-
encodeInputBase
protected void encodeInputBase(java.io.DataOutputStream os) throws java.io.IOException
- Throws:
java.io.IOException
-
decode
public static Input decode(java.io.InputStream is) throws java.io.IOException
Decodes the input fromencode()
.- Parameters:
is
- the data to decode from- Returns:
- the decoded input
- Throws:
java.io.IOException
- if it fails to decode part of the input
-
decodeInputBase
protected static void decodeInputBase(java.io.DataInputStream dis, Input input) throws java.io.IOException
- Throws:
java.io.IOException
-
deepEquals
public boolean deepEquals(java.lang.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 java.lang.String toString()
*- Overrides:
toString
in classjava.lang.Object
-
-