Mojo function
conv2d
conv2d(input: Symbol, filter: Symbol, stride: Tuple[Int, Int] = VariadicPack(<store_to_mem({1}), store_to_mem({1})>, 1), dilation: Tuple[Int, Int] = VariadicPack(<store_to_mem({1}), store_to_mem({1})>, 1), padding: Tuple[Int, Int, Int, Int] = VariadicPack(<store_to_mem({0}), store_to_mem({0}), store_to_mem({0}), store_to_mem({0})>, 1), groups: Int = 1) -> Symbol
Computes the 2-D convolution product of the input with the given filter, strides, dilations, paddings, and groups.
The op supports 2-D convolution, with the following layout assumptions:
- input has NHWC layout, i.e., (batch_size, height, width, in_channels)
- filter has layout RSCF, i.e., (height, width, in_channels / num_groups, out_channels)
The padding values are expected to take the form (pad_dim1_before,
pad_dim1_after, pad_dim2_before, pad_dim2_after...) and represent padding
0's before and after the indicated spatial dimensions in input
. In 2-D
convolution, dim1 here repesents H and dim2 represents W. In Python like
syntax, padding a 2x3 spatial input
with [0, 1, 2, 1] would yield:
input = [
[1, 2, 3],
[4, 5, 6]
]
# Shape is 2x3
padded_input = [
[0, 0, 1, 2, 3, 0],
[0, 0, 4, 5, 6, 0]
[0, 0, 0, 0, 0, 0]
]
# Shape is 3x6
This op currently only supports strides and padding on the input.
Args:
- βinput (
Symbol
): An NHWC input tensor to perform the convolution upon. - βfilter (
Symbol
): The convolution filter in RSCF layout: (height, width, in_channels / num_groups, out_channels). - βstride (
Tuple[Int, Int]
): The stride of the convolution operation. - βdilation (
Tuple[Int, Int]
): The spacing between the kernel points. - βpadding (
Tuple[Int, Int, Int, Int]
): The amount of padding applied to the input. - βgroups (
Int
): When greater than 1, divides the convolution into multiple parallel convolutions. The number of input and output channels must both be divisible by the number of groups.
Returns:
A symbolic tensor value with the convolution applied.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
If you'd like to share more information, please report an issue on GitHub
π What went wrong?