Package ai.djl.nn.convolutional
Class Conv1d
- java.lang.Object
-
- ai.djl.nn.AbstractBaseBlock
-
- ai.djl.nn.AbstractBlock
-
- ai.djl.nn.convolutional.Convolution
-
- ai.djl.nn.convolutional.Conv1d
-
- All Implemented Interfaces:
Block
public class Conv1d extends Convolution
AConv1d
layer works similar toConvolution
layer with the exception of the number of dimension it operates on being only one, which isLayoutType.WIDTH
. The channel of the input data may be more than one, depending on what data is processed. Each filter slides through the data with only one direction of movement along the dimension itself.Commonly, this kind of convolution layer, as proposed in this paper is used in tasks utilizing serial data, enabling convolutional processing of 1-dimensional data such as time-series data (stock price, weather, ECG) and text/speech data without the need of transforming it to 2-dimensional data to be processed by
Conv2d
, though this is quite a common technique as well.The input to a
Conv1d
is anNDList
with a single 3-DNDArray
. The layout of theNDArray
must be "NCW". The shapes aredata: (batch_size, channel, width)
weight: (num_filter, channel, kernel[0])
bias: (num_filter,)
out: (batch_size, num_filter, out_width)
out_width = f(width, kernel[0], pad[0], stride[0], dilate[0])
where f(x, k, p, s, d) = floor((x + 2 * p - d * (k - 1) - 1)/s) + 1
Both
weight
andbias
are learn-able parameters.- See Also:
Convolution
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Conv1d.Builder
-
Nested classes/interfaces inherited from class ai.djl.nn.convolutional.Convolution
Convolution.ConvolutionBuilder<T extends Convolution.ConvolutionBuilder>
-
-
Field Summary
-
Fields inherited from class ai.djl.nn.convolutional.Convolution
bias, dilation, filters, groups, includeBias, kernelShape, padding, stride, weight
-
Fields inherited from class ai.djl.nn.AbstractBlock
children, parameters
-
Fields inherited from class ai.djl.nn.AbstractBaseBlock
inputNames, inputShapes, version
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Conv1d.Builder
builder()
Creates a builder to build aConv1d
.static NDList
conv1d(NDArray input, NDArray weight)
Applies 1D convolution over an input signal composed of several input planes.static NDList
conv1d(NDArray input, NDArray weight, NDArray bias)
Applies 1D convolution over an input signal composed of several input planes.static NDList
conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride)
Applies 1D convolution over an input signal composed of several input planes.static NDList
conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride, Shape padding)
Applies 1D convolution over an input signal composed of several input planes.static NDList
conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride, Shape padding, Shape dilation)
Applies 1D convolution over an input signal composed of several input planes.static NDList
conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride, Shape padding, Shape dilation, int groups)
Applies 1D convolution over an input signal composed of several input planes.protected LayoutType[]
getExpectedLayout()
Returns the expected layout of the input.protected java.lang.String
getStringLayout()
Returns the string representing the layout of the input.protected int
numDimensions()
Returns the number of dimensions of the input.-
Methods inherited from class ai.djl.nn.convolutional.Convolution
beforeInitialize, forwardInternal, getDilation, getFilters, getGroups, getKernelShape, getOutputShapes, getPadding, getStride, isIncludeBias, loadMetadata, prepare
-
Methods inherited from class ai.djl.nn.AbstractBlock
addChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParameters
-
Methods inherited from class ai.djl.nn.AbstractBaseBlock
cast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getParameters, initialize, initializeChildBlocks, isInitialized, loadParameters, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ai.djl.nn.Block
forward, freezeParameters
-
-
-
-
Method Detail
-
getExpectedLayout
protected LayoutType[] getExpectedLayout()
Returns the expected layout of the input.- Specified by:
getExpectedLayout
in classConvolution
- Returns:
- the expected layout of the input
-
getStringLayout
protected java.lang.String getStringLayout()
Returns the string representing the layout of the input.- Specified by:
getStringLayout
in classConvolution
- Returns:
- the string representing the layout of the input
-
numDimensions
protected int numDimensions()
Returns the number of dimensions of the input.- Specified by:
numDimensions
in classConvolution
- Returns:
- the number of dimensions of the input
-
conv1d
public static NDList conv1d(NDArray input, NDArray weight)
Applies 1D convolution over an input signal composed of several input planes.- Parameters:
input
- the inputNDArray
of shape (batchSize, inputChannel, width)weight
- filtersNDArray
of shape (outChannel, inputChannel/groups, width)- Returns:
- the output of the conv1d operation
-
conv1d
public static NDList conv1d(NDArray input, NDArray weight, NDArray bias)
Applies 1D convolution over an input signal composed of several input planes.- Parameters:
input
- the inputNDArray
of shape (batchSize, inputChannel, width)weight
- filtersNDArray
of shape (outChannel, inputChannel/groups, width)bias
- biasNDArray
of shape (outChannel)- Returns:
- the output of the conv1d operation
-
conv1d
public static NDList conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride)
Applies 1D convolution over an input signal composed of several input planes.- Parameters:
input
- the inputNDArray
of shape (batchSize, inputChannel, width)weight
- filtersNDArray
of shape (outChannel, inputChannel/groups, width)bias
- biasNDArray
of shape (outChannel)stride
- the stride of the convolving kernel: Shape(width)- Returns:
- the output of the conv1d operation
-
conv1d
public static NDList conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride, Shape padding)
Applies 1D convolution over an input signal composed of several input planes.- Parameters:
input
- the inputNDArray
of shape (batchSize, inputChannel, width)weight
- filtersNDArray
of shape (outChannel, inputChannel/groups, width)bias
- biasNDArray
of shape (outChannel)stride
- the stride of the convolving kernel: Shape(width)padding
- implicit paddings on both sides of the input: Shape(width)- Returns:
- the output of the conv1d operation
-
conv1d
public static NDList conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride, Shape padding, Shape dilation)
Applies 1D convolution over an input signal composed of several input planes.- Parameters:
input
- the inputNDArray
of shape (batchSize, inputChannel, width)weight
- filtersNDArray
of shape (outChannel, inputChannel/groups, width)bias
- biasNDArray
of shape (outChannel)stride
- the stride of the convolving kernel: Shape(width)padding
- implicit paddings on both sides of the input: Shape(width)dilation
- the spacing between kernel elements: Shape(width)- Returns:
- the output of the conv1d operation
-
conv1d
public static NDList conv1d(NDArray input, NDArray weight, NDArray bias, Shape stride, Shape padding, Shape dilation, int groups)
Applies 1D convolution over an input signal composed of several input planes.- Parameters:
input
- the inputNDArray
of shape (batchSize, inputChannel, width)weight
- filtersNDArray
of shape (outChannel, inputChannel/groups, width)bias
- biasNDArray
of shape (outChannel)stride
- the stride of the convolving kernel: Shape(width)padding
- implicit paddings on both sides of the input: Shape(width)dilation
- the spacing between kernel elements: Shape(width)groups
- split input into groups: input channel(input.size(1)) should be divisible by the number of groups- Returns:
- the output of the conv1d operation
-
builder
public static Conv1d.Builder builder()
Creates a builder to build aConv1d
.- Returns:
- a new builder
-
-