public class ParallelBlock extends AbstractBlock
ParallelBlock
is a Block
whose children form a parallel branch in the network and
are combined to produce a single output.
ParallelBlock
has no direct parameters.
inputNames, inputShapes
Constructor and Description |
---|
ParallelBlock(java.util.function.Function<java.util.List<NDList>,NDList> function)
Creates a parallel block whose branches are combined to form a single output by the given
function.
|
ParallelBlock(java.util.function.Function<java.util.List<NDList>,NDList> function,
java.util.List<Block> blocks)
Creates a parallel block whose branches are formed by each block in the list of blocks, and
are combined to form a single output by the given function.
|
Modifier and Type | Method and Description |
---|---|
ParallelBlock |
add(Block block)
Adds the given
Block to the block, which is one parallel branch. |
ParallelBlock |
add(java.util.function.Function<NDList,NDList> f)
Adds a
LambdaBlock , that applies the given function, to the list of parallel
branches. |
ParallelBlock |
addAll(Block... blocks)
Adds an array of blocks, each of which is a parallel branch.
|
ParallelBlock |
addAll(java.util.Collection<Block> blocks)
Adds a
Collection of blocks, each of which is a parallel branch. |
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
boolean training,
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[] inputShapes)
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 |
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, readInputShapes, saveInputShapes, setInitializer, setInitializer
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forward, validateLayout
public ParallelBlock(java.util.function.Function<java.util.List<NDList>,NDList> function)
function
- the function to define how the parallel branches are combined to form a
single outputpublic ParallelBlock(java.util.function.Function<java.util.List<NDList>,NDList> function, java.util.List<Block> blocks)
function
- the function to define how the parallel branches are combinedblocks
- the blocks that form each of the parallel branchespublic final ParallelBlock addAll(Block... blocks)
blocks
- the array of blocks to addpublic final ParallelBlock addAll(java.util.Collection<Block> blocks)
Collection
of blocks, each of which is a parallel branch.blocks
- the Collection
of blocks to addpublic final ParallelBlock add(Block block)
Block
to the block, which is one parallel branch.block
- the block to be added as a parallel branchpublic final ParallelBlock add(java.util.function.Function<NDList,NDList> f)
LambdaBlock
, that applies the given function, to the list of parallel
branches.f
- the function that forms the LambdaBlock
public NDList forward(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
parameterStore
- the parameter storeinputs
- the input NDListtraining
- true for a training forward passparams
- 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[] inputShapes)
manager
- an NDManagerinputShapes
- the shapes of the inputspublic java.util.List<Parameter> getDirectParameters()
Parameter
public 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