Package ai.djl.nn.core
Class Prelu
java.lang.Object
ai.djl.nn.AbstractBaseBlock
ai.djl.nn.AbstractBlock
ai.djl.nn.core.Prelu
- All Implemented Interfaces:
Block
Applies Leaky Parametric ReLU activation element-wise to the input.
Leaky ReLUs attempt to fix the 'dying ReLU' problem by allowing a small slope when the input is negative and has a slope of one when input is positive. This is defined by \(y= x \gt 0 ? x : slope * x\).
Parametric ReLU is a Leaky ReLU in which the slope is learnt during training.
-
Field Summary
Fields inherited from class ai.djl.nn.AbstractBlock
children, parametersFields inherited from class ai.djl.nn.AbstractBaseBlock
inputNames, inputShapes, outputDataTypes, version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected NDListforwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)after initialization.Shape[]getOutputShapes(Shape[] inputs) Returns the expected output shapes of the block for the specified input shapes.voidloadMetadata(byte loadVersion, DataInputStream is) Overwrite this to load additional metadata with the parameter values.static NDListApplies a Prelu activation on the inputNDArray.Methods inherited from class ai.djl.nn.AbstractBlock
addChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParametersMethods inherited from class ai.djl.nn.AbstractBaseBlock
beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initialize, initializeChildBlocks, isInitialized, loadParameters, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ai.djl.nn.Block
forward, freezeParameters, freezeParameters, getOutputShapes
-
Constructor Details
-
Prelu
public Prelu()Creates a Parametric ReLU Block.
-
-
Method Details
-
forwardInternal
protected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)after initialization.- Specified by:
forwardInternalin classAbstractBaseBlock- Parameters:
parameterStore- the parameter storeinputs- the input NDListtraining- true for a training forward passparams- optional parameters- Returns:
- the output of the forward pass
-
getOutputShapes
Returns the expected output shapes of the block for the specified input shapes.- Parameters:
inputs- the shapes of the inputs- Returns:
- the expected output shapes of the block
-
loadMetadata
public void loadMetadata(byte loadVersion, DataInputStream is) throws 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 probably need to overwrite this. This default implementation checks if the version number fits, if not it throws anMalformedModelException. After that it restores the input shapes.- Overrides:
loadMetadatain classAbstractBaseBlock- Parameters:
loadVersion- the version used for loading this metadata.is- the input stream we are loading from- Throws:
IOException- loading failedMalformedModelException- data can be loaded but has wrong format
-
prelu
Applies a Prelu activation on the inputNDArray.Prelu is defined as \(y = max(0,x) + alpha * min(0, x) \) where alpha is learnable parameter
-