Class Convolution
- All Implemented Interfaces:
- Block
While convolution process itself has been around for quite some time in mathematics, in 1998 LeCun et al. implemented the very first convolution layers forming a network called LeNet-5 for character recognition task; details of the network's implementation can be find in LeNet-5's paper. When other approaches at that time used handcrafted features with external stage of feature extraction, convolution layer performed feature extraction on its own with no human interference. This marks a new era of machine-extracted features, but it was not until 2012 that the published paper of AlexNet marked the beginning of convolutional neural networks, which by the name itself heavily relies on convolution layer.
Convolution layer is usually used in image-related tasks due to its well-renowned performance as shown by existing works and currently, other non-image-related fields of study are beginning to incorporate convolution layer as an addition or replacement of previous approaches, with one example being time series processing with 1-dimensional convolution layer. Due to the nature of convolution that processes all points in the input data, it is computationally expensive, hence the use of GPU is strongly recommended for faster performance as opposed to using CPU. Note that it is also common to stack convolution layers with different output channels for more representations of the input data.
Current implementations of Convolution are Conv1d with input dimension of
 LayoutType.WIDTH, Conv2d with input dimension of LayoutType.WIDTH and
 LayoutType.HEIGHT, and lastly Conv3d with input dimension of LayoutType.WIDTH, LayoutType.HEIGHT, and LayoutType.DEPTH. These implementations
 share the same core principal as a Convolution layer does, with the difference being the
 number of input dimension each operates on as denoted by ConvXD for X
 dimension(s).
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA builder that can build anyConvolutionblock.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Parameterprotected Shapeprotected intprotected intprotected booleanprotected Shapeprotected Shapeprotected Shapeprotected ParameterFields inherited from class ai.djl.nn.AbstractBlockchildren, parametersFields inherited from class ai.djl.nn.AbstractBaseBlockinputNames, inputShapes, outputDataTypes, version
- 
Constructor SummaryConstructorsConstructorDescriptionConvolution(Convolution.ConvolutionBuilder<?> builder) Creates aConvolutionobject.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidbeforeInitialize(Shape... inputShapes) Performs any action necessary before initialization.protected NDListforwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)after initialization.Returns the dilation along each dimension.protected abstract LayoutType[]Returns the expected layout of the input.intReturns the required number of filters.intReturns the number of group partitions.Returns the shape of the kernel.Shape[]getOutputShapes(Shape[] inputs) Returns the expected output shapes of the block for the specified input shapes.Returns the padding along each dimension.Returns the stride of the convolution.protected abstract StringReturns the string representing the layout of the input.booleanReturns whether to include a bias vector.voidloadMetadata(byte loadVersion, DataInputStream is) Overwrite this to load additional metadata with the parameter values.protected abstract intReturns the number of dimensions of the input.protected voidSets the shape ofParameters.Methods inherited from class ai.djl.nn.AbstractBlockaddChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParametersMethods inherited from class ai.djl.nn.AbstractBaseBlockcast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initialize, initializeChildBlocks, isInitialized, loadParameters, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ai.djl.nn.Blockforward, freezeParameters, freezeParameters, getOutputShapes
- 
Field Details- 
kernelShape
- 
stride
- 
padding
- 
dilation
- 
filtersprotected int filters
- 
groupsprotected int groups
- 
includeBiasprotected boolean includeBias
- 
weight
- 
bias
 
- 
- 
Constructor Details- 
ConvolutionCreates aConvolutionobject.- Parameters:
- builder- the- Builderthat has the necessary configurations
 
 
- 
- 
Method Details- 
getExpectedLayoutReturns the expected layout of the input.- Returns:
- the expected layout of the input
 
- 
getStringLayoutReturns the string representing the layout of the input.- Returns:
- the string representing the layout of the input
 
- 
numDimensionsprotected abstract int numDimensions()Returns the number of dimensions of the input.- Returns:
- the number of dimensions of the input
 
- 
forwardInternalprotected 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 class- AbstractBaseBlock
- Parameters:
- parameterStore- the parameter store
- inputs- the input NDList
- training- true for a training forward pass
- params- optional parameters
- Returns:
- the output of the forward pass
 
- 
beforeInitializePerforms any action necessary before initialization. For example, keep the input information or verify the layout.- Overrides:
- beforeInitializein class- AbstractBaseBlock
- Parameters:
- inputShapes- the expected shapes of the input
 
- 
prepareSets the shape ofParameters.- Overrides:
- preparein class- AbstractBaseBlock
- Parameters:
- inputs- the shapes of inputs
 
- 
getOutputShapesReturns 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
 
- 
loadMetadatapublic 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 class- AbstractBaseBlock
- Parameters:
- loadVersion- the version used for loading this metadata.
- is- the input stream we are loading from
- Throws:
- IOException- loading failed
- MalformedModelException- data can be loaded but has wrong format
 
- 
getKernelShapeReturns the shape of the kernel.- Returns:
- the shape of the kernel
 
- 
getStrideReturns the stride of the convolution.- Returns:
- the stride of the convolution
 
- 
getPaddingReturns the padding along each dimension.- Returns:
- the padding along each dimension
 
- 
getDilationReturns the dilation along each dimension.- Returns:
- the dilation along each dimension
 
- 
getFilterspublic int getFilters()Returns the required number of filters.- Returns:
- the required number of filters
 
- 
getGroupspublic int getGroups()Returns the number of group partitions.- Returns:
- the number of group partitions
 
- 
isIncludeBiaspublic boolean isIncludeBias()Returns whether to include a bias vector.- Returns:
- whether to include a bias vector
 
 
-