Package ai.djl.nn

Class ParallelBlock

  • All Implemented Interfaces:
    Block

    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.

    • Constructor Detail

      • ParallelBlock

        public 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.
        Parameters:
        function - the function to define how the parallel branches are combined to form a single output
      • ParallelBlock

        public 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.
        Parameters:
        function - the function to define how the parallel branches are combined
        blocks - the blocks that form each of the parallel branches
    • Method Detail

      • addAll

        public final ParallelBlock addAll​(Block... blocks)
        Adds an array of blocks, each of which is a parallel branch.
        Parameters:
        blocks - the array of blocks to add
        Returns:
        this block
      • addAll

        public final ParallelBlock addAll​(java.util.Collection<Block> blocks)
        Adds a Collection of blocks, each of which is a parallel branch.
        Parameters:
        blocks - the Collection of blocks to add
        Returns:
        this block
      • add

        public final ParallelBlock add​(Block block)
        Adds the given Block to the block, which is one parallel branch.
        Parameters:
        block - the block to be added as a parallel branch
        Returns:
        this block
      • add

        public final ParallelBlock add​(java.util.function.Function<NDList,​NDList> f)
        Adds a LambdaBlock, that applies the given function, to the list of parallel branches.
        Parameters:
        f - the function that forms the LambdaBlock
        Returns:
        this block
      • add

        public ParallelBlock add​(java.util.function.Function<NDList,​NDList> f,
                                 java.lang.String name)
        Adds a LambdaBlock, that applies the given function, to the list of parallel branches.
        Parameters:
        f - the function forms the LambdaBlock
        name - the function name
        Returns:
        this block
      • initializeChildBlocks

        public void initializeChildBlocks​(NDManager manager,
                                          DataType dataType,
                                          Shape... inputShapes)
        Initializes the Child blocks of this block. You need to override this method if your subclass has child blocks. Used to determine the correct input shapes for child blocks based on the requested input shape for this block.
        Overrides:
        initializeChildBlocks in class AbstractBaseBlock
        Parameters:
        manager - the manager to use for initialization
        dataType - the requested data type
        inputShapes - the expected input shapes for this block
      • getOutputShapes

        public Shape[] getOutputShapes​(Shape[] inputShapes)
        Returns the expected output shapes of the block for the specified input shapes.
        Parameters:
        inputShapes - the shapes of the inputs
        Returns:
        the expected output shapes of the block
      • loadMetadata

        public void loadMetadata​(byte loadVersion,
                                 java.io.DataInputStream is)
                          throws java.io.IOException,
                                 MalformedModelException
        Overwrite this to load additional metadata with the parameter values.

        If you overwrite AbstractBaseBlock.saveMetadata(DataOutputStream) or need to provide backward compatibility to older binary formats, you prabably need to overwrite this. This default implementation checks if the version number fits, if not it throws an MalformedModelException. After that it restores the input shapes.

        Overrides:
        loadMetadata in class AbstractBaseBlock
        Parameters:
        loadVersion - the version used for loading this metadata.
        is - the input stream we are loading from
        Throws:
        java.io.IOException - loading failed
        MalformedModelException - data can be loaded but has wrong format