Conv#

  • Domain: ai.onnx

  • Since version: 22

The convolution operator consumes an input tensor and a filter, and computes the output.

Inputs

  • X (T): Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 … x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE …].

  • W (T): The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x … x kn), where (k1 x k2 x … kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL …]. Assuming zero based indices for the shape array, X.shape[1] == (W.shape[1] * group) == C and W.shape[0] mod G == 0. Or in other words FILTER_IN_CHANNEL multiplied by the number of groups should be equal to DATA_CHANNEL and the number of feature maps M should be a multiple of the number of groups G.

  • B (T): Optional 1D bias to be added to the convolution, has size of M.

Outputs

  • Y (T): Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.

Type Constraints

  • T: Constrain input and output types to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).

Examples#

test_cc_basic_conv_with_padding

Node:
  Conv(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    pads = [1, 1, 1, 1]
Inputs:
  X: shape=(1, 1, 5, 5), dtype=float32
    [[[[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., 24.]]]]
  W: shape=(1, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 1, 5, 5), dtype=float32
    [[[[ 12.,  21.,  27.,  33.,  24.],
       [ 33.,  54.,  63.,  72.,  51.],
       [ 63.,  99., 108., 117.,  81.],
       [ 93., 144., 153., 162., 111.],
       [ 72., 111., 117., 123.,  84.]]]]

test_cc_basic_conv_without_padding

Node:
  Conv(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
Inputs:
  X: shape=(1, 1, 5, 5), dtype=float32
    [[[[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., 24.]]]]
  W: shape=(1, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 1, 3, 3), dtype=float32
    [[[[ 54.,  63.,  72.],
       [ 99., 108., 117.],
       [144., 153., 162.]]]]

test_cc_conv_fp16

Node:
  Conv(X, W, B) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    pads = [1, 1, 1, 1]
Inputs:
  X: shape=(1, 1, 4, 4), dtype=float16
    [[[[0. , 0.5, 1. , 1.5],
       [2. , 2.5, 3. , 3.5],
       [4. , 4.5, 5. , 5.5],
       [6. , 6.5, 7. , 7.5]]]]
  W: shape=(1, 1, 3, 3), dtype=float16
    [[[[0.25, 0.25, 0.25],
       [0.25, 0.25, 0.25],
       [0.25, 0.25, 0.25]]]]
  B: shape=(1,), dtype=float16
    [0.5]

Outputs:
  Y: shape=(1, 1, 4, 4), dtype=float16
    [[[[ 1.75 ,  2.75 ,  3.5  ,  2.75 ],
       [ 3.875,  6.125,  7.25 ,  5.375],
       [ 6.875, 10.625, 11.75 ,  8.375],
       [ 5.75 ,  8.75 ,  9.5  ,  6.75 ]]]]

test_cc_conv_with_autopad_same

Node:
  Conv(X, W, B) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    auto_pad = "SAME_UPPER"
Inputs:
  X: shape=(1, 1, 4, 4), dtype=float32
    [[[[ 0.,  1.,  2.,  3.],
       [ 4.,  5.,  6.,  7.],
       [ 8.,  9., 10., 11.],
       [12., 13., 14., 15.]]]]
  W: shape=(1, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]
  B: shape=(1,), dtype=float32
    [0.5]

Outputs:
  Y: shape=(1, 1, 4, 4), dtype=float32
    [[[[10.5, 18.5, 24.5, 18.5],
       [27.5, 45.5, 54.5, 39.5],
       [51.5, 81.5, 90.5, 63.5],
       [42.5, 66.5, 72.5, 50.5]]]]

test_cc_conv_with_strides_and_asymmetric_padding

Node:
  Conv(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    pads = [1, 0, 1, 0]
    strides = [2, 2]
Inputs:
  X: shape=(1, 1, 7, 5), dtype=float32
    [[[[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., 24.],
       [25., 26., 27., 28., 29.],
       [30., 31., 32., 33., 34.]]]]
  W: shape=(1, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 1, 4, 2), dtype=float32
    [[[[ 21.,  33.],
       [ 99., 117.],
       [189., 207.],
       [171., 183.]]]]

test_cc_conv_with_strides_no_padding

Node:
  Conv(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    strides = [2, 2]
Inputs:
  X: shape=(1, 1, 7, 5), dtype=float32
    [[[[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., 24.],
       [25., 26., 27., 28., 29.],
       [30., 31., 32., 33., 34.]]]]
  W: shape=(1, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 1, 3, 2), dtype=float32
    [[[[ 54.,  72.],
       [144., 162.],
       [234., 252.]]]]

test_cc_conv_with_strides_padding

Node:
  Conv(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    pads = [1, 1, 1, 1]
    strides = [2, 2]
Inputs:
  X: shape=(1, 1, 7, 5), dtype=float32
    [[[[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., 24.],
       [25., 26., 27., 28., 29.],
       [30., 31., 32., 33., 34.]]]]
  W: shape=(1, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 1, 4, 3), dtype=float32
    [[[[ 12.,  27.,  24.],
       [ 63., 108.,  81.],
       [123., 198., 141.],
       [112., 177., 124.]]]]

Differences with previous version (11)#

SchemaDiff: Conv (domain 'ai.onnx')

  • old version: 11

  • new version: 22

  • breaking: no

Type constraints:

  • changed ‘T’: added types: [‘tensor(bfloat16)’]

Version History#