Col2Im#
Domain:
ai.onnxSince version: 18
The operator rearranges column blocks back into a multidimensional image
Col2Im behaves similarly to PyTorch’s fold https://pytorch.org/docs/stable/generated/torch.nn.Fold.html, but it only supports *batched* multi-dimensional image tensors. Another implementation in Python with N-dimension support can be found at f-dangel/unfoldNd.
NOTE:
Although specifying image_shape looks redundant because it could be calculated from
convolution formulas, it is required as input for more advanced scenarios as explained
at PyTorch's implementation (https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Col2Im.cpp#L10)
Inputs
input (T): Input data tensor to be rearranged from column blocks back into an image. This is a 3-dimensional tensor containing [N, C * n-ary-product(block_shape), L], where N is batch dimension, C is image channel dimension and L is number of blocks.The blocks are enumerated in increasing lexicographic-order of their indices.For example, with an image-size 10*20 and block-size 9*18, there would be 2*3 blocks, enumerated in the order block(0, 0), block(0, 1), block(0, 2), block(1, 0), block(1, 1), block(1, 2).
image_shape (tensor(int64)): The shape of the spatial dimensions of the image after rearranging the column blocks.This is a 1-dimensional tensor with size of at least 2, containing the value [H_img, W_img] for a 2-D image or [dim_i1, dim_i2, …, dim_iN] for a N-D image.
block_shape (tensor(int64)): The shape of the block to apply on the input.This is a 1-dimensional tensor of size of at least 2, containing the value [H_block, W_block] for a 2-D image or [dim_b1, dim_b2, …, dim_bN] for a N-D block.This is the block-shape before dilation is applied to it.
Outputs
output (T): Output tensor produced by rearranging blocks into an image.
Attributes
dilations (int[]): 1-dimensional tensor with dilation value along each spatial axis of the image. If not present, the dilation defaults to 1 along each spatial axis of the image.
pads (int[]): 1-dimensional tensor with padding value for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis.
padsformat should be as follow [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin is the number of pixels added at the beginning of axisiand xi_end is the number of pixels added at the end of axisi. If not present, the padding defaults to 0 along start and end of each spatial axis.strides (int[]): 1-dimensional tensor with stride value along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
Type Constraints
T: Constrain input and output types to all numeric tensor types. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).
Examples#
test_cc_col2im
Node:
Col2Im(input, image_shape, block_shape) -> (output)
Inputs:
input: shape=(1, 5, 5), dtype=float32
[[[ 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.]]]
image_shape: shape=(2,), dtype=int64
[5, 5]
block_shape: shape=(2,), dtype=int64
[1, 5]
Outputs:
output: shape=(1, 1, 5, 5), dtype=float32
[[[[ 1., 6., 11., 16., 21.],
[ 2., 7., 12., 17., 22.],
[ 3., 8., 13., 18., 23.],
[ 4., 9., 14., 19., 24.],
[ 5., 10., 15., 20., 25.]]]]
test_cc_col2im_5d
Node:
Col2Im(input, image_shape, block_shape) -> (output)
Inputs:
input: shape=(1, 10, 12), dtype=float32
[[[ 1., 2., 3., ..., 10., 11., 12.],
[ 13., 14., 15., ..., 22., 23., 24.],
[ 25., 26., 27., ..., 34., 35., 36.],
...,
[ 85., 86., 87., ..., 94., 95., 96.],
[ 97., 98., 99., ..., 106., 107., 108.],
[109., 110., 111., ..., 118., 119., 120.]]]
image_shape: shape=(3,), dtype=int64
[3, 4, 5]
block_shape: shape=(3,), dtype=int64
[1, 1, 5]
Outputs:
output: shape=(1, 2, 3, 4, 5), dtype=float32
[[[[[ 1., 13., 25., 37., 49.],
[ 2., 14., 26., 38., 50.],
[ 3., 15., 27., 39., 51.],
[ 4., 16., 28., 40., 52.]],
[[ 5., 17., 29., 41., 53.],
[ 6., 18., 30., 42., 54.],
[ 7., 19., 31., 43., 55.],
[ 8., 20., 32., 44., 56.]],
[[ 9., 21., 33., 45., 57.],
[ 10., 22., 34., 46., 58.],
[ 11., 23., 35., 47., 59.],
[ 12., 24., 36., 48., 60.]]],
[[[ 61., 73., 85., 97., 109.],
[ 62., 74., 86., 98., 110.],
[ 63., 75., 87., 99., 111.],
[ 64., 76., 88., 100., 112.]],
[[ 65., 77., 89., 101., 113.],
[ 66., 78., 90., 102., 114.],
[ 67., 79., 91., 103., 115.],
[ 68., 80., 92., 104., 116.]],
[[ 69., 81., 93., 105., 117.],
[ 70., 82., 94., 106., 118.],
[ 71., 83., 95., 107., 119.],
[ 72., 84., 96., 108., 120.]]]]]
test_cc_col2im_dilations
Node:
Col2Im(input, image_shape, block_shape) -> (output)
Attributes:
dilations = [1, 5]
Inputs:
input: shape=(1, 4, 5), dtype=float32
[[[ 1., 2., 3., 4., 5.],
[ 6., 7., 8., 9., 10.],
[11., 12., 13., 14., 15.],
[16., 17., 18., 19., 20.]]]
image_shape: shape=(2,), dtype=int64
[6, 6]
block_shape: shape=(2,), dtype=int64
[2, 2]
Outputs:
output: shape=(1, 1, 6, 6), dtype=float32
[[[[ 1., 0., 0., 0., 0., 6.],
[13., 0., 0., 0., 0., 23.],
[15., 0., 0., 0., 0., 25.],
[17., 0., 0., 0., 0., 27.],
[19., 0., 0., 0., 0., 29.],
[15., 0., 0., 0., 0., 20.]]]]
test_cc_col2im_pads
Node:
Col2Im(input, image_shape, block_shape) -> (output)
Attributes:
pads = [0, 1, 0, 1]
Inputs:
input: shape=(1, 5, 15), dtype=float32
[[[ 1., 2., 3., ..., 13., 14., 15.],
[16., 17., 18., ..., 28., 29., 30.],
[31., 32., 33., ..., 43., 44., 45.],
[46., 47., 48., ..., 58., 59., 60.],
[61., 62., 63., ..., 73., 74., 75.]]]
image_shape: shape=(2,), dtype=int64
[5, 5]
block_shape: shape=(2,), dtype=int64
[1, 5]
Outputs:
output: shape=(1, 1, 5, 5), dtype=float32
[[[[ 18., 51., 96., 141., 110.],
[ 24., 60., 105., 150., 116.],
[ 30., 69., 114., 159., 122.],
[ 36., 78., 123., 168., 128.],
[ 42., 87., 132., 177., 134.]]]]
test_cc_col2im_strides
Node:
Col2Im(input, image_shape, block_shape) -> (output)
Attributes:
strides = [2, 2]
Inputs:
input: shape=(1, 9, 4), dtype=float32
[[[ 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.]]]
image_shape: shape=(2,), dtype=int64
[5, 5]
block_shape: shape=(2,), dtype=int64
[3, 3]
Outputs:
output: shape=(1, 1, 5, 5), dtype=float32
[[[[ 1., 5., 11., 6., 10.],
[13., 17., 35., 18., 22.],
[28., 36., 74., 38., 46.],
[15., 19., 39., 20., 24.],
[27., 31., 63., 32., 36.]]]]