Package ai.djl.modality
Class Input
java.lang.Object
ai.djl.modality.Input
- Direct Known Subclasses:
Output
A class stores the generic input data for inference.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(byte[] data) Appends an item at the end of the input.void
add
(int index, 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
Appends an item at the end of the input.void
Adds a key/value pair to the input content.void
add
(String key, BytesSupplier data) Adds a key/value pair to the input content.void
Adds a key/value pair to the input content.void
addProperty
(String key, String value) Adds a property to the input.static Input
decode
(InputStream is) Decodes the input fromencode()
.protected static void
decodeInputBase
(DataInputStream dis, Input input) boolean
deepEquals
(Object o) Checks for deep equality with another input.byte[]
encode()
Encodes all data in the input to a binary form.protected void
get
(int index) Returns the element at the specified position in theInput
.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
(String key) Returns the value asbyte[]
for the first key found in theInput
.getAsNDArray
(NDManager manager, int index) Returns the value asNDArray
at the specified position in theInput
.getAsNDArray
(NDManager manager, String key) Returns the value asNDArray
for the first key found in theInput
.getAsNDList
(NDManager manager, int index) Returns the value asNDList
at the specified position in theInput
.getAsNDList
(NDManager manager, String key) Returns the value asNDList
for the first key found in theInput
.getAsString
(int index) Returns the value asbyte[]
at the specified position in theInput
.getAsString
(String key) Returns the value asbyte[]
for the first key found in theInput
.ai.djl.util.PairList<String,
BytesSupplier> Returns the content of the input.ai.djl.util.PairList<String,
ByteBuffer> Returns the content of the input asByteBuffer
s.getData()
Returns the default data item.getDataAsNDList
(NDManager manager) Returns the default data asNDList
.Returns the properties of the input.getProperty
(String key, String defaultValue) Returns the value to which the specified key is mapped.boolean
Returnstrue
if the input is cancelled.void
setCancelled
(boolean cancelled) Sets the cancelled status.void
setContent
(ai.djl.util.PairList<String, BytesSupplier> content) Sets the content of the input.void
setProperties
(Map<String, String> properties) Sets the properties of the input.toString()
*
-
Field Details
-
properties
-
-
-
Constructor Details
-
Input
public Input()Constructs a newInput
instance.
-
-
Method Details
-
isCancelled
public boolean isCancelled()Returnstrue
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
Returns the properties of the input.- Returns:
- the properties of the input
-
setProperties
Sets the properties of the input.- Parameters:
properties
- the properties of the input
-
addProperty
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
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
Returns the content of the input.A
Input
may contains multiple data.- Returns:
- the content of the input
-
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
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
Appends an item at the end of the input.- Parameters:
data
- data to be added
-
add
Appends an item at the end of the input.- Parameters:
data
- data to be added
-
add
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
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
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
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
Returns the default data item.- Returns:
- the default data item
-
getDataAsNDList
Returns the default data asNDList
.- Parameters:
manager
-NDManager
used to create thisNDArray
- Returns:
- the default data as
NDList
-
get
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
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
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
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
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
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
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
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
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
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
- Throws:
IOException
-
decode
Decodes the input fromencode()
.- Parameters:
is
- the data to decode from- Returns:
- the decoded input
- Throws:
IOException
- if it fails to decode part of the input
-
decodeInputBase
- Throws:
IOException
-
deepEquals
Checks for deep equality with another input.- Parameters:
o
- the other input.- Returns:
- whether they and all properties, content, and data are equal
-
toString
*
-