public class LambdaBlock extends AbstractBlock
LambdaBlock is a Block with no parameters or children.
LambdaBlock allows converting any function that takes an NDList as input and
returns an NDList into a parameter-less and child-less Block. This can be useful
in converting activation functions, identity blocks, and more. For example, identity block can be
created as new LambdaBlock(x -> x).
children, inputNames, inputShapes, parameters, version| Constructor and Description |
|---|
LambdaBlock(java.util.function.Function<NDList,NDList> lambda)
Creates a LambdaBlock that can apply the specified function.
|
| Modifier and Type | Method and Description |
|---|---|
protected NDList |
forwardInternal(ParameterStore parameterStore,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A helper for
Block.forward(ParameterStore, NDList, boolean, PairList) after
initialization. |
Shape[] |
getOutputShapes(Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.
|
void |
loadParameters(NDManager manager,
java.io.DataInputStream is)
Loads the parameters from the given input stream.
|
static LambdaBlock |
singleton(java.util.function.Function<NDArray,NDArray> lambda)
Creates a
LambdaBlock for a singleton function. |
java.lang.String |
toString() |
addChildBlock, addParameter, beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getChildren, getDirectParameters, getParameters, initialize, initializeChildBlocks, isInitialized, loadMetadata, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, validateLayoutpublic static LambdaBlock singleton(java.util.function.Function<NDArray,NDArray> lambda)
LambdaBlock for a singleton function.lambda - a function accepting a singleton NDList and returning another sinleton
NDListLambdaBlock for the functionprotected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Block.forward(ParameterStore, NDList, boolean, PairList) after
initialization.forwardInternal in class AbstractBlockparameterStore - the parameter storeinputs - the input NDListtraining - true for a training forward passparams - optional parameterspublic Shape[] getOutputShapes(Shape[] inputShapes)
inputShapes - the shapes of the inputspublic void loadParameters(NDManager manager, java.io.DataInputStream is) throws java.io.IOException, MalformedModelException
loadParameters in interface BlockloadParameters in class AbstractBlockmanager - 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 AbstractBlock