Package ai.djl.nn

Class AbstractBlock

    • Field Detail

      • children

        protected BlockList children
        All direct children of this Block. Keys are names of the blocks.

        Use the addChildBlock(String, Block) method to add children. All children in this map are automagically loaded / saved.

      • parameters

        protected java.util.LinkedHashMap<java.lang.String,​Parameter> parameters
        All direct parameters of this Block. Keys are name of the parameters.

        Use the addParameter(Parameter) method to add children. All parameters in this map are automatically loaded / saved.

    • Constructor Detail

      • AbstractBlock

        public AbstractBlock()
        Constructs a new AbstractBlock instance.
      • AbstractBlock

        public AbstractBlock​(byte version)
        Builds an empty block with the given version for parameter serialization.
        Parameters:
        version - the version to use for parameter serialization.
    • Method Detail

      • addChildBlock

        protected final <B extends Block> B addChildBlock​(java.lang.String name,
                                                          B block)
        Use this to add a child block to this block.
        Type Parameters:
        B - The type of block
        Parameters:
        name - Name of the block, must not be null.
        block - The block, must not be null.
        Returns:
        the block given as a parameter - that way the block can be created and reassigned to a member variable more easily.
      • addChildBlock

        protected LambdaBlock addChildBlock​(java.lang.String name,
                                            java.util.function.Function<NDList,​NDList> f)
        Adds a LambdaBlock as a child block to this block.
        Parameters:
        name - Name of the block, must not be null.
        f - the function forms the LambdaBlock
        Returns:
        the child block
      • addParameter

        protected final <P extends Parameter> P addParameter​(P parameter)
        Adds a parameter to this block. If parameters are added with this method, intialization of the parameter works out of the box
        Type Parameters:
        P - the specific parameter subclass
        Parameters:
        parameter - the parameter to add, not null
        Returns:
        the parameter passed as arguments to make it easier to create and assign parameters in one line
      • getChildren

        public BlockList getChildren()
        Returns a list of all the children of the block.
        Returns:
        the list of child blocks
      • getDirectParameters

        public ParameterList getDirectParameters()
        Returns a list of all the direct parameters of the block.
        Returns:
        the list of Parameter