represents a trainable convolutional net layer having n output channels and using kernels of size s to compute the convolution.


represents a layer performing one-dimensional convolutions with kernels of size s.


represents a layer performing two-dimensional convolution with kernels of size h×w.


includes options for padding and other parameters.

Details and Options

  • ConvolutionLayer[n,] represents a layer that, applied to an input tensor with m input channels and one or more spatial dimensions, effectively performs n×m distinct convolutions across the spatial dimensions to produce an output tensor with n channels. The channel dimension is taken to be the first dimension of the input and output tensors.
  • In ConvolutionLayer[n,s], the dimensionality of the convolution layer will be inferred when the layer is connected in a NetChain, NetGraph, etc.
  • The following optional parameters can be included:
  • "Biases"Automaticinitial vector of kernel biases
    "Dilation"1dilation factor
    "Dimensionality"Automaticnumber of spatial dimensions of the convolution
    "PaddingSize"0amount of zero padding to apply to the input
    "Stride"1convolution step size to use
    "Weights"Automaticinitial tensor of kernel weights
  • The settings for "PaddingSize", "Dilation" and "Stride" can be of the following forms:
  • nuse the value n for all dimensions
    {,ni,}use the value ni for the i^(th) dimension
  • With Automatic settings, weights and biases are added automatically when NetInitialize or NetTrain is used.
  • The setting "Biases"->None specifies that no biases should be used.
  • If weights and biases have been added, ConvolutionLayer[][input] explicitly computes the output from applying the layer.
  • ConvolutionLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • NetExtract can be used to extract weights and biases from a ConvolutionLayer object.
  • ConvolutionLayer is typically used inside NetChain, NetGraph, etc.
  • ConvolutionLayer exposes the following ports for use in NetGraph etc.:
  • "Input"a matrix or rank-3 tensor
    "Output"a matrix or rank-3 tensor
  • When it cannot be inferred from other layers in a larger net, the option "Input"->{d1,,dn} can be used to fix the input dimensions of ConvolutionLayer.
  • Given an input tensor of dimensions d1××di×, the output tensor will be of dimensions 1××i×, where the channel dimension 1=n and the sizes di are transformed according to , where is the padding size, is the kernel size, is the stride size, and is the dilation factor for each dimension.


open allclose all

Basic Examples  (2)

Create a one-dimensional ConvolutionLayer with 2 output channels and a kernel size of 4:

Click for copyable input

Create an initialized one-dimensional ConvolutionLayer:

Click for copyable input

Apply the layer to an input matrix:

Click for copyable input

Scope  (3)

Options  (15)

Properties & Relations  (2)

Possible Issues  (3)

See Also

DeconvolutionLayer  PoolingLayer  BatchNormalizationLayer  LocalResponseNormalizationLayer  NetChain  NetGraph  NetInitialize  NetTrain  NetExtract  Ramp  SpatialTransformationLayer

Introduced in 2016
| Updated in 2017