public class SequentialBlock extends AbstractBlock
SequentialBlock is a Block whose children form a chain of blocks with each child
block feeding its output to the next. The output of the last child is returned as the output of
the SequentialBlock.
SequentialBlock has no direct parameters.
inputNames, inputShapes| Constructor and Description |
|---|
SequentialBlock() |
| Modifier and Type | Method and Description |
|---|---|
SequentialBlock |
add(Block block)
Adds the given
Block to the block to be executed in order. |
SequentialBlock |
add(java.util.function.Function<NDList,NDList> f)
Adds a
LambdaBlock that applies the given function to the sequence of blocks. |
SequentialBlock |
addAll(Block... blocks)
Adds an array of blocks to be executed in sequence, in order.
|
SequentialBlock |
addAll(java.util.Collection<Block> blocks)
Adds a
Collection of blocks to be executed in sequence, in order. |
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Applies the operating function of the block once.
|
BlockList |
getChildren()
Returns a list of all the children of the block.
|
java.util.List<Parameter> |
getDirectParameters()
Returns a list of all the direct parameters of the block.
|
Shape[] |
getOutputShapes(NDManager manager,
Shape[] inputs)
Returns the expected output shapes of the block for the specified input shapes.
|
Shape |
getParameterShape(java.lang.String name,
Shape[] inputShapes)
Returns the shape of the specified direct parameter of this block given the shapes of the
input to the block.
|
Shape[] |
initialize(NDManager manager,
DataType dataType,
Shape... inputShapes)
Initializes the parameters of the block.
|
void |
loadParameters(NDManager manager,
java.io.DataInputStream is)
Loads the parameters from the given input stream.
|
void |
removeLastBlock()
Removes the
Block added last from the sequence of blocks. |
void |
replaceLastBlock(Block block)
Replaces the
Block last added from the sequence of blocks, and adds the given block. |
void |
saveParameters(java.io.DataOutputStream os)
Writes the parameters of the block to the given outputStream.
|
java.lang.String |
toString() |
beforeInitialize, cast, clear, describeInput, getParameters, isInitialized, setInitializer, setInitializerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, validateLayoutpublic SequentialBlock addAll(Block... blocks)
blocks - the array of blockspublic SequentialBlock addAll(java.util.Collection<Block> blocks)
Collection of blocks to be executed in sequence, in order.blocks - the Collection of blockspublic SequentialBlock add(Block block)
Block to the block to be executed in order.block - the block to be added to the sequence of blockspublic SequentialBlock add(java.util.function.Function<NDList,NDList> f)
LambdaBlock that applies the given function to the sequence of blocks.f - the function forms the LambdaBlockpublic void removeLastBlock()
Block added last from the sequence of blocks.public void replaceLastBlock(Block block)
Block last added from the sequence of blocks, and adds the given block.block - the block to replace the last block withpublic NDList forward(ParameterStore parameterStore, NDList inputs, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
parameterStore - the parameter storeinputs - the input NDListparams - optional parameterspublic Shape[] initialize(NDManager manager, DataType dataType, Shape... inputShapes)
manager - the NDManager to initialize the parametersdataType - the datatype of the parametersinputShapes - the shapes of the inputs to the blockpublic Shape[] getOutputShapes(NDManager manager, Shape[] inputs)
manager - an NDManagerinputs - the shapes of the inputspublic java.util.List<Parameter> getDirectParameters()
Parameterpublic Shape getParameterShape(java.lang.String name, Shape[] inputShapes)
name - the name of the parameterinputShapes - the shapes of the input to the blockpublic BlockList getChildren()
public void saveParameters(java.io.DataOutputStream os)
throws java.io.IOException
os - the outputstream to save the parameters tojava.io.IOException - if an I/O error occurspublic void loadParameters(NDManager manager, java.io.DataInputStream is) throws java.io.IOException, MalformedModelException
manager - an NDManager to create the parameter arraysis - the inputstream that stream the parameter valuesjava.io.IOException - if an I/O error occursMalformedModelException - if the model file is corrupted or unsupportedpublic java.lang.String toString()
toString in class java.lang.Object