ConvolutionLayer

ConvolutionLayer[n,s]

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

ConvolutionLayer[n,{s}]

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

ConvolutionLayer[n,{h,w}]

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

ConvolutionLayer[n,{h,w,d}]

represents a three-dimensional convolutions with kernels of size h×w×d.

ConvolutionLayer[n,kernel,opts]

includes options for padding and other parameters.

Details and Options

  • ConvolutionLayer[n,] represents a layer that, applied to an input array with m input channels and one or more spatial dimensions, effectively performs n×m distinct convolutions across the spatial dimensions to produce an output array with n channels.
  • ConvolutionLayer[][input] explicitly computes the output from applying the layer to input.
  • ConvolutionLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • 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
    "ChannelGroups"1number of channel groups
    "Dilation"1dilation factor
    "Dimensionality"Automaticnumber of spatial dimensions of the convolution
    "Interleaving"Falsethe position of the channel dimension
    "PaddingSize"0amount of zero padding to apply to the input
    "Stride"1convolution step size to use
    "Weights"Automaticinitial array of kernel weights
  • The setting for "PaddingSize" can be of the following forms:
  • npad every dimension with n zeros on the beginning and end
    {n1,n2,}pad the i^(th) dimension with n zeros on the beginning and end
    {{n1,m1},{n2,m2},}pad the i^(th) dimension with ni zeros at the beginning and mi zeros at the end
  • The settings for "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
  • By setting "GroupNumber"g, the m input channels and n output channels are split into g groups of m/g and n/g channels, respectively, where m and n are required to be divisible by g. Separate convolutions are performed connecting the i^(th) group of input channels with the i^(th) group of output channels, and results are concatenated in the output. Each input/output group pair is connected by n/g×m/g convolutions, so setting "GroupNumber"g effectively reduces the number of distinct convolutions from n×m to n×m/g.
  • 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.
  • With the setting "Interleaving"->False, the channel dimension is taken to be the first dimension of the input and output arrays.
  • With the setting "Interleaving"->True, the channel dimension is taken to be the last dimension of the input and output arrays.
  • 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"an array of rank 2, 3 or 4
    "Output"an array of rank 2, 3 or 4
  • ConvolutionLayer can operate on arrays that contain "Varying" dimensions.
  • 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 array of dimensions d1××di×, the output array will be of dimensions ×××, where the channel dimension =n and the sizes di are transformed according to , where / are the padding sizes at the beginning/end of the axis, is the kernel size, is the stride size, and is the dilation factor for each dimension.

Examples

open all close all

Basic Examples  (2)

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

In[1]:=
Click for copyable input
Out[1]=

Create an initialized one-dimensional ConvolutionLayer:

In[1]:=
Click for copyable input
Out[1]=

Apply the layer to an input matrix:

In[2]:=
Click for copyable input
Out[2]=

Scope  (3)

Options  (17)

Properties & Relations  (2)

Possible Issues  (3)

Introduced in 2016
(11.0)
|
Updated in 2019
(12.0)