public abstract class TransformerBaseBlock extends AbstractBlock
| Modifier and Type | Field and Description |
|---|---|
protected java.util.LinkedHashMap<java.lang.String,Block> |
children
All direct children of this Block.
|
protected java.util.LinkedHashMap<java.lang.String,Parameter> |
parameters
All direct parameters of this Block.
|
protected java.util.LinkedHashMap<java.lang.String,java.util.function.Function<Shape[],Shape>> |
parameterShapeCallbacks
Callbacks to determine the shape of a parameter.
|
protected int |
version
The model version of this block, used for checking if parameters are still valid during
parameter loading.
|
inputNames, inputShapes| Constructor and Description |
|---|
TransformerBaseBlock(int version)
Builds an empty block with the given version for parameter serialization.
|
| Modifier and Type | Method and Description |
|---|---|
protected <B extends Block> |
addChildBlock(java.lang.String name,
B block)
Adds a child block to this block.
|
protected <P extends Parameter> |
addParameter(P parameter)
Adds a parameter to this block.
|
protected <P extends Parameter> |
addParameter(P parameter,
java.util.function.Function<Shape[],Shape> shapeCallback)
Adds a parameter to this block.
|
protected <P extends Parameter> |
addParameter(P parameter,
Shape shape)
Adds a parameter to this block.
|
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 |
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.
|
int |
getVersion()
Returns the version number to be used for parameter serialization.
|
Shape[] |
initialize(NDManager manager,
DataType dataType,
Shape... inputShapes)
Initializes the parameters of the block.
|
abstract void |
initializeChildBlocks(NDManager manager,
DataType dataType,
Shape... inputShapes)
Initializes the Child blocks of this 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.
|
beforeInitialize, cast, clear, describeInput, getParameters, isInitialized, readInputShapes, saveInputShapes, setInitializer, setInitializerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforward, forward, getOutputShapes, validateLayoutprotected int version
protected java.util.LinkedHashMap<java.lang.String,Block> children
addChildBlock(String, Block) method to add children. All children in
this map are automagically loaded / saved.protected java.util.LinkedHashMap<java.lang.String,Parameter> parameters
addParameter(Parameter) method to add children. All parameters in this
map are automagically loaded / saved.protected java.util.LinkedHashMap<java.lang.String,java.util.function.Function<Shape[],Shape>> parameterShapeCallbacks
Block.getParameterShape(String, Shape[]) and implement
parameter shape resolution manually.public TransformerBaseBlock(int version)
version - the version to use for parameter serialization.public int getVersion()
protected <B extends Block> B addChildBlock(java.lang.String name, B block)
B - The type of blockname - Name of the block, must be unique or otherwise existing children with this name
are removed, must not be null.block - The block, must not be null.protected <P extends Parameter> P addParameter(P parameter)
Block.getParameterShape(String, Shape[]) and return the shapes of parameters
themselves.P - the specific parameter subclassparameter - the parameter to add, not nullprotected <P extends Parameter> P addParameter(P parameter, Shape shape)
P - the specific parameter subclassparameter - the parameter to add, not nullshape - the shape of the parameterprotected <P extends Parameter> P addParameter(P parameter, java.util.function.Function<Shape[],Shape> shapeCallback)
P - the specific parameter subclassparameter - the parameter to add, not nullshapeCallback - the method to call once the input shape of this block is known to
determine the shape of the given parameterpublic Shape getParameterShape(java.lang.String name, Shape[] inputShapes)
Blockname - the name of the parameterinputShapes - the shapes of the input to the blockpublic BlockList getChildren()
Blockpublic 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 abstract void initializeChildBlocks(NDManager manager, DataType dataType, Shape... inputShapes)
manager - the manager to use for initializationdataType - the requested data typeinputShapes - the expected input shapespublic java.util.List<Parameter> getDirectParameters()
BlockParameterpublic void saveParameters(java.io.DataOutputStream os)
throws java.io.IOException
Blockos - 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
Blockmanager - 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 unsupported