Package ai.djl.translate
Class SimplePaddingStackBatchifier
- java.lang.Object
-
- ai.djl.translate.SimplePaddingStackBatchifier
-
- All Implemented Interfaces:
Batchifier
,java.io.Serializable
public final class SimplePaddingStackBatchifier extends java.lang.Object implements Batchifier
A simpler version of thePaddingStackBatchifier
that pads all dimensions rather than specific ones.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface ai.djl.translate.Batchifier
STACK
-
-
Constructor Summary
Constructors Constructor Description SimplePaddingStackBatchifier()
A simpleBatchifier
that pads all arrays to same shape (with padding 0) and then stacks them.SimplePaddingStackBatchifier(float padding)
A simpleBatchifier
that pads all arrays to same shape and then stacks them.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NDList
batchify(NDList[] inputs)
NDList[]
split(NDList list, int numOfSlices, boolean evenSplit)
NDList[]
unbatchify(NDList inputs)
-
-
-
Constructor Detail
-
SimplePaddingStackBatchifier
public SimplePaddingStackBatchifier(float padding)
A simpleBatchifier
that pads all arrays to same shape and then stacks them.- Parameters:
padding
- the number of pad with
-
SimplePaddingStackBatchifier
public SimplePaddingStackBatchifier()
A simpleBatchifier
that pads all arrays to same shape (with padding 0) and then stacks them.
-
-
Method Detail
-
batchify
public NDList batchify(NDList[] inputs)
Converts an array ofRecord
NDList
s into a combinedBatch
NDList.The size of the input array is the batch size. The data in each of the
NDList
are assumed to be the same, and are batched together to form one batchedNDList
.- Specified by:
batchify
in interfaceBatchifier
- Parameters:
inputs
- the input array ofNDList
where each element is a- Returns:
- the batchified
NDList
-
unbatchify
public NDList[] unbatchify(NDList inputs)
Splits a combinedBatch
NDList
into it's constituentRecord
NDList
s.This reverses the
batchify
operation.- Specified by:
unbatchify
in interfaceBatchifier
- Parameters:
inputs
- theNDList
that needs to be 'unbatchified'- Returns:
- an array of NDLists, of size equal to batch size, where each NDList is one element from the batch of inputs
-
split
public NDList[] split(NDList list, int numOfSlices, boolean evenSplit)
Partitions the givenBatch
NDList
into multipleBatch
lists with smaller batch size.As an example, this function might be used for multi-GPU training where it takes the main batch and splits it into sub-batches that can be run on each GPU.
This function unbatchifies the input
NDList
, redistributes them into the given number of slices, and then batchify each of the slices to form an array ofNDList
.- Specified by:
split
in interfaceBatchifier
- Parameters:
list
- theNDList
that needs to be splitnumOfSlices
- the number of slices the list must be sliced intoevenSplit
- whether each slice must have the same shape- Returns:
- an array of
NDList
that contains all the slices
-
-