ConvTranspose#

  • Domain: ai.onnx

  • Since version: 22

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

If the pads parameter is provided the shape of the output is calculated via the following equation:

output_shape[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - pads[start_i] - pads[end_i]

output_shape can also be explicitly specified in which case pads values are auto generated using these equations:

total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i]
If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2)
Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2).

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)

  • W (T): The weight tensor that will be used in the convolutions; has size (C x M/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 weight shape will be (C x M/group x k1 x k2 x … x kn), where (k1 x k2 x … x kn) is the dimension of the kernel. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)

  • 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, pad lengths and group count. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)

Type Constraints

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

Examples#

test_cc_convtranspose

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]]]]
  W: shape=(1, 2, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]],

      [[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 2, 5, 5), dtype=float32
    [[[[ 0.,  1.,  3.,  3.,  2.],
       [ 3.,  8., 15., 12.,  7.],
       [ 9., 21., 36., 27., 15.],
       [ 9., 20., 33., 24., 13.],
       [ 6., 13., 21., 15.,  8.]],

      [[ 0.,  1.,  3.,  3.,  2.],
       [ 3.,  8., 15., 12.,  7.],
       [ 9., 21., 36., 27., 15.],
       [ 9., 20., 33., 24., 13.],
       [ 6., 13., 21., 15.,  8.]]]]

test_cc_convtranspose_1d

Node:
  ConvTranspose(X, W) -> (Y)
Inputs:
  X: shape=(1, 1, 3), dtype=float32
    [[[0., 1., 2.]]]
  W: shape=(1, 2, 3), dtype=float32
    [[[1., 1., 1.],
      [1., 1., 1.]]]

Outputs:
  Y: shape=(1, 2, 5), dtype=float32
    [[[0., 1., 3., 3., 2.],
      [0., 1., 3., 3., 2.]]]

test_cc_convtranspose_3d

Node:
  ConvTranspose(X, W) -> (Y)
Inputs:
  X: shape=(1, 1, 3, 4, 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.],
        [35., 36., 37., 38., 39.]],

       [[40., 41., 42., 43., 44.],
        [45., 46., 47., 48., 49.],
        [50., 51., 52., 53., 54.],
        [55., 56., 57., 58., 59.]]]]]
  W: shape=(1, 2, 3, 3, 3), dtype=float32
    [[[[[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]],

       [[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]],

       [[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]]],


      [[[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]],

       [[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]],

       [[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]]]]]

Outputs:
  Y: shape=(1, 2, 5, 6, 7), dtype=float32
    [[[[[  0.,   1.,   3., ...,   9.,   7.,   4.],
        [  5.,  12.,  21., ...,  33.,  24.,  13.],
        [ 15.,  33.,  54., ...,  72.,  51.,  27.],
        [ 30.,  63.,  99., ..., 117.,  81.,  42.],
        [ 25.,  52.,  81., ...,  93.,  64.,  33.],
        [ 15.,  31.,  48., ...,  54.,  37.,  19.]],

       [[ 20.,  42.,  66., ...,  78.,  54.,  28.],
        [ 50., 104., 162., ..., 186., 128.,  66.],
        [ 90., 186., 288., ..., 324., 222., 114.],
        [120., 246., 378., ..., 414., 282., 144.],
        [ 90., 184., 282., ..., 306., 208., 106.],
        [ 50., 102., 156., ..., 168., 114.,  58.]],

       [[ 60., 123., 189., ..., 207., 141.,  72.],
        [135., 276., 423., ..., 459., 312., 159.],
        [225., 459., 702., ..., 756., 513., 261.],
        [270., 549., 837., ..., 891., 603., 306.],
        [195., 396., 603., ..., 639., 432., 219.],
        [105., 213., 324., ..., 342., 231., 117.]],

       [[ 60., 122., 186., ..., 198., 134.,  68.],
        [130., 264., 402., ..., 426., 288., 146.],
        [210., 426., 648., ..., 684., 462., 234.],
        [240., 486., 738., ..., 774., 522., 264.],
        [170., 344., 522., ..., 546., 368., 186.],
        [ 90., 182., 276., ..., 288., 194.,  98.]],

       [[ 40.,  81., 123., ..., 129.,  87.,  44.],
        [ 85., 172., 261., ..., 273., 184.,  93.],
        [135., 273., 414., ..., 432., 291., 147.],
        [150., 303., 459., ..., 477., 321., 162.],
        [105., 212., 321., ..., 333., 224., 113.],
        [ 55., 111., 168., ..., 174., 117.,  59.]]],


      [[[  0.,   1.,   3., ...,   9.,   7.,   4.],
        [  5.,  12.,  21., ...,  33.,  24.,  13.],
        [ 15.,  33.,  54., ...,  72.,  51.,  27.],
        [ 30.,  63.,  99., ..., 117.,  81.,  42.],
        [ 25.,  52.,  81., ...,  93.,  64.,  33.],
        [ 15.,  31.,  48., ...,  54.,  37.,  19.]],

       [[ 20.,  42.,  66., ...,  78.,  54.,  28.],
        [ 50., 104., 162., ..., 186., 128.,  66.],
        [ 90., 186., 288., ..., 324., 222., 114.],
        [120., 246., 378., ..., 414., 282., 144.],
        [ 90., 184., 282., ..., 306., 208., 106.],
        [ 50., 102., 156., ..., 168., 114.,  58.]],

       [[ 60., 123., 189., ..., 207., 141.,  72.],
        [135., 276., 423., ..., 459., 312., 159.],
        [225., 459., 702., ..., 756., 513., 261.],
        [270., 549., 837., ..., 891., 603., 306.],
        [195., 396., 603., ..., 639., 432., 219.],
        [105., 213., 324., ..., 342., 231., 117.]],

       [[ 60., 122., 186., ..., 198., 134.,  68.],
        [130., 264., 402., ..., 426., 288., 146.],
        [210., 426., 648., ..., 684., 462., 234.],
        [240., 486., 738., ..., 774., 522., 264.],
        [170., 344., 522., ..., 546., 368., 186.],
        [ 90., 182., 276., ..., 288., 194.,  98.]],

       [[ 40.,  81., 123., ..., 129.,  87.,  44.],
        [ 85., 172., 261., ..., 273., 184.,  93.],
        [135., 273., 414., ..., 432., 291., 147.],
        [150., 303., 459., ..., 477., 321., 162.],
        [105., 212., 321., ..., 333., 224., 113.],
        [ 55., 111., 168., ..., 174., 117.,  59.]]]]]

test_cc_convtranspose_autopad_same

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    auto_pad = "SAME_UPPER"
    strides = [2, 2]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]]]]
  W: shape=(1, 2, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]],

      [[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 2, 6, 6), dtype=float32
    [[[[ 0.,  0.,  1.,  1.,  3.,  2.],
       [ 0.,  0.,  1.,  1.,  3.,  2.],
       [ 3.,  3.,  8.,  5., 12.,  7.],
       [ 3.,  3.,  7.,  4.,  9.,  5.],
       [ 9.,  9., 20., 11., 24., 13.],
       [ 6.,  6., 13.,  7., 15.,  8.]],

      [[ 0.,  0.,  1.,  1.,  3.,  2.],
       [ 0.,  0.,  1.,  1.,  3.,  2.],
       [ 3.,  3.,  8.,  5., 12.,  7.],
       [ 3.,  3.,  7.,  4.,  9.,  5.],
       [ 9.,  9., 20., 11., 24., 13.],
       [ 6.,  6., 13.,  7., 15.,  8.]]]]

test_cc_convtranspose_dilations

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    dilations = [2, 2]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[3., 8., 1.],
       [9., 5., 7.],
       [3., 2., 6.]]]]
  W: shape=(1, 1, 2, 2), dtype=float32
    [[[[7., 2.],
       [1., 9.]]]]

Outputs:
  Y: shape=(1, 1, 5, 5), dtype=float32
    [[[[21., 56., 13., 16.,  2.],
       [63., 35., 67., 10., 14.],
       [24., 22., 76., 76., 21.],
       [ 9.,  5., 88., 45., 63.],
       [ 3.,  2., 33., 18., 54.]]]]

test_cc_convtranspose_group_2

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    group = 2
Inputs:
  X: shape=(1, 2, 3, 3), dtype=float32
    [[[[ 0.,  1.,  2.],
       [ 3.,  4.,  5.],
       [ 6.,  7.,  8.]],

      [[ 9., 10., 11.],
       [12., 13., 14.],
       [15., 16., 17.]]]]
  W: shape=(2, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]],


     [[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 2, 5, 5), dtype=float32
    [[[[  0.,   1.,   3.,   3.,   2.],
       [  3.,   8.,  15.,  12.,   7.],
       [  9.,  21.,  36.,  27.,  15.],
       [  9.,  20.,  33.,  24.,  13.],
       [  6.,  13.,  21.,  15.,   8.]],

      [[  9.,  19.,  30.,  21.,  11.],
       [ 21.,  44.,  69.,  48.,  25.],
       [ 36.,  75., 117.,  81.,  42.],
       [ 27.,  56.,  87.,  60.,  31.],
       [ 15.,  31.,  48.,  33.,  17.]]]]

test_cc_convtranspose_group_2_image_3

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    group = 2
Inputs:
  X: shape=(3, 2, 3, 3), 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.]],

      [[ 9., 10., 11.],
       [12., 13., 14.],
       [15., 16., 17.]]],


     [[[ 0.,  1.,  2.],
       [ 3.,  4.,  5.],
       [ 6.,  7.,  8.]],

      [[ 9., 10., 11.],
       [12., 13., 14.],
       [15., 16., 17.]]]]
  W: shape=(2, 1, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]],


     [[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(3, 2, 5, 5), dtype=float32
    [[[[  0.,   1.,   3.,   3.,   2.],
       [  3.,   8.,  15.,  12.,   7.],
       [  9.,  21.,  36.,  27.,  15.],
       [  9.,  20.,  33.,  24.,  13.],
       [  6.,  13.,  21.,  15.,   8.]],

      [[  9.,  19.,  30.,  21.,  11.],
       [ 21.,  44.,  69.,  48.,  25.],
       [ 36.,  75., 117.,  81.,  42.],
       [ 27.,  56.,  87.,  60.,  31.],
       [ 15.,  31.,  48.,  33.,  17.]]],


     [[[ 18.,  37.,  57.,  39.,  20.],
       [ 39.,  80., 123.,  84.,  43.],
       [ 63., 129., 198., 135.,  69.],
       [ 45.,  92., 141.,  96.,  49.],
       [ 24.,  49.,  75.,  51.,  26.]],

      [[  9.,  19.,  30.,  21.,  11.],
       [ 21.,  44.,  69.,  48.,  25.],
       [ 36.,  75., 117.,  81.,  42.],
       [ 27.,  56.,  87.,  60.,  31.],
       [ 15.,  31.,  48.,  33.,  17.]]],


     [[[  0.,   1.,   3.,   3.,   2.],
       [  3.,   8.,  15.,  12.,   7.],
       [  9.,  21.,  36.,  27.,  15.],
       [  9.,  20.,  33.,  24.,  13.],
       [  6.,  13.,  21.,  15.,   8.]],

      [[  9.,  19.,  30.,  21.,  11.],
       [ 21.,  44.,  69.,  48.,  25.],
       [ 36.,  75., 117.,  81.,  42.],
       [ 27.,  56.,  87.,  60.,  31.],
       [ 15.,  31.,  48.,  33.,  17.]]]]

test_cc_convtranspose_kernel_shape

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    strides = [3, 2]
    output_shape = [10, 8]
    kernel_shape = [3, 3]
    output_padding = [1, 1]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]]]]
  W: shape=(1, 2, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]],

      [[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 2, 10, 8), dtype=float32
    [[[[ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       ...,
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]],

      [[ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       ...,
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]]]]

test_cc_convtranspose_output_shape

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    strides = [3, 2]
    output_shape = [10, 8]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]]]]
  W: shape=(1, 2, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]],

      [[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 2, 10, 8), dtype=float32
    [[[[ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       ...,
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]],

      [[ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       [ 0.,  0.,  1., ...,  2.,  2.,  0.],
       ...,
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 6.,  6., 13., ...,  8.,  8.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]]]]

test_cc_convtranspose_pads

Node:
  ConvTranspose(X, W) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
    pads = [1, 2, 1, 2]
    strides = [3, 2]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]]]]
  W: shape=(1, 2, 3, 3), dtype=float32
    [[[[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]],

      [[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]]]

Outputs:
  Y: shape=(1, 2, 7, 3), dtype=float32
    [[[[ 1.,  1.,  3.],
       [ 1.,  1.,  3.],
       [ 7.,  4.,  9.],
       [ 7.,  4.,  9.],
       [ 7.,  4.,  9.],
       [13.,  7., 15.],
       [13.,  7., 15.]],

      [[ 1.,  1.,  3.],
       [ 1.,  1.,  3.],
       [ 7.,  4.,  9.],
       [ 7.,  4.,  9.],
       [ 7.,  4.,  9.],
       [13.,  7., 15.],
       [13.,  7., 15.]]]]

test_cc_convtranspose_with_kernel

Node:
  ConvTranspose(X, W, B) -> (Y)
  Attributes:
    kernel_shape = [3, 3]
Inputs:
  X: shape=(1, 1, 3, 3), dtype=float32
    [[[[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]]]]
  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, 5, 5), dtype=float32
    [[[[ 0.5,  1.5,  3.5,  3.5,  2.5],
       [ 3.5,  8.5, 15.5, 12.5,  7.5],
       [ 9.5, 21.5, 36.5, 27.5, 15.5],
       [ 9.5, 20.5, 33.5, 24.5, 13.5],
       [ 6.5, 13.5, 21.5, 15.5,  8.5]]]]

Differences with previous version (11)#

SchemaDiff: ConvTranspose (domain 'ai.onnx')

  • old version: 11

  • new version: 22

  • breaking: no

Type constraints:

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

Version History#