Docs
Spacial Ops

Spatial Operations

Spacial ops are operations that are applied to spatial data like images, videos, etc. These operations are used in convolutional neural networks (CNNs) to extract features from the input data.

conv1d

def conv1d(input: Array, weight: Array, bias: Array = None, stride: Int = 1, padding: Int = 0, dilation: Int = 1, groups: Int = 1) -> Array
Applies a 1D convolution over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C_in, L_in) weight: Filters of shape (C_out, C_in/groups, L_kernel) bias: Optional bias tensor of shape (C_out) stride: The stride of the convolving kernel padding: Implicit padding on both sides of the input dilation: The spacing between kernel elements groups: Number of blocked connections from input channels to output channels

Returns

Output tensor of shape (N, C_out, L_out)

conv2d

def conv2d(input: Array, weight: Array, bias: Array = None, stride: Tuple[Int, Int] = (1, 1), padding: Tuple[Int, Int] = (0, 0), dilation: Tuple[Int, Int] = (1, 1), groups: Int = 1) -> Array
Applies a 2D convolution over an input image composed of several input planes.
Args

input: Input tensor of shape (N, C_in, H_in, W_in) weight: Filters of shape (C_out, C_in/groups, H_kernel, W_kernel) bias: Optional bias tensor of shape (C_out) stride: The stride of the convolving kernel padding: Implicit padding on both sides of the input dilation: The spacing between kernel elements groups: Number of blocked connections from input channels to output channels

Returns

Output tensor of shape (N, C_out, H_out, W_out)

conv3d

def conv3d(input: Array, weight: Array, bias: Array = None, stride: Tuple[Int, Int, Int] = (1, 1, 1), padding: Tuple[Int, Int, Int] = (0, 0, 0), dilation: Tuple[Int, Int, Int] = (1, 1, 1), groups: Int = 1) -> Array
Applies a 3D convolution over an input volume composed of several input planes.
Args

input: Input tensor of shape (N, C_in, D_in, H_in, W_in) weight: Filters of shape (C_out, C_in/groups, D_kernel, H_kernel, W_kernel) bias: Optional bias tensor of shape (C_out) stride: The stride of the convolving kernel padding: Implicit padding on both sides of the input dilation: The spacing between kernel elements groups: Number of blocked connections from input channels to output channels

Returns

Output tensor of shape (N, C_out, D_out, H_out, W_out)

max_pool1d

def max_pool1d(input: Array, kernel_size: Int, stride: Int = None, padding: Int = 0, dilation: Int = 1, return_indices: Bool = False, ceil_mode: Bool = False) -> Array
Applies a 1D max pooling over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C, L_in) kernel_size: The size of the window to take a max over stride: The stride of the window. Default value is kernel_size padding: Implicit zero padding to be added on both sides dilation: A parameter that controls the stride of elements in the window return_indices: If True, will return the max indices along with the outputs ceil_mode: When True, will use ceil instead of floor to compute the output shape

Returns

Output tensor of shape (N, C, L_out)

max_pool2d

def max_pool2d(input: Array, kernel_size: Tuple[Int, Int], stride: Tuple[Int, Int] = None, padding: Tuple[Int, Int] = (0, 0), dilation: Tuple[Int, Int] = (1, 1), return_indices: Bool = False, ceil_mode: Bool = False) -> Array
Applies a 2D max pooling over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C, H_in, W_in) kernel_size: The size of the window to take a max over stride: The stride of the window. Default value is kernel_size padding: Implicit zero padding to be added on both sides dilation: A parameter that controls the stride of elements in the window return_indices: If True, will return the max indices along with the outputs ceil_mode: When True, will use ceil instead of floor to compute the output shape

Returns

Output tensor of shape (N, C, H_out, W_out)

max_pool3d

def max_pool3d(input: Array, kernel_size: Tuple[Int, Int, Int], stride: Tuple[Int, Int, Int] = None, padding: Tuple[Int, Int, Int] = (0, 0, 0), dilation: Tuple[Int, Int, Int] = (1, 1, 1), return_indices: Bool = False, ceil_mode: Bool = False) -> Array
Applies a 3D max pooling over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C, D_in, H_in, W_in) kernel_size: The size of the window to take a max over stride: The stride of the window. Default value is kernel_size padding: Implicit zero padding to be added on both sides dilation: A parameter that controls the stride of elements in the window return_indices: If True, will return the max indices along with the outputs ceil_mode: When True, will use ceil instead of floor to compute the output shape

Returns

Output tensor of shape (N, C, D_out, H_out, W_out)

avg_pool1d

def avg_pool1d(input: Array, kernel_size: Int, stride: Int = None, padding: Int = 0, ceil_mode: Bool = False, count_include_pad: Bool = True) -> Array
Applies a 1D average pooling over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C, L_in) kernel_size: The size of the window stride: The stride of the window. Default value is kernel_size padding: Implicit zero padding to be added on both sides ceil_mode: When True, will use ceil instead of floor to compute the output shape count_include_pad: When True, will include the zero-padding in the averaging calculation

Returns

Output tensor of shape (N, C, L_out)

avg_pool2d

def avg_pool2d(input: Array, kernel_size: Tuple[Int, Int], stride: Tuple[Int, Int] = None, padding: Tuple[Int, Int] = (0, 0), ceil_mode: Bool = False, count_include_pad: Bool = True) -> Array
Applies a 2D average pooling over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C, H_in, W_in) kernel_size: The size of the window stride: The stride of the window. Default value is kernel_size padding: Implicit zero padding to be added on both sides ceil_mode: When True, will use ceil instead of floor to compute the output shape count_include_pad: When True, will include the zero-padding in the averaging calculation

Returns

Output tensor of shape (N, C, H_out, W_out)

avg_pool3d

def avg_pool3d(input: Array, kernel_size: Tuple[Int, Int, Int], stride: Tuple[Int, Int, Int] = None, padding: Tuple[Int, Int, Int] = (0, 0, 0), ceil_mode: Bool = False, count_include_pad: Bool = True) -> Array
Applies a 3D average pooling over an input signal composed of several input planes.
Args

input: Input tensor of shape (N, C, D_in, H_in, W_in) kernel_size: The size of the window stride: The stride of the window. Default value is kernel_size padding: Implicit zero padding to be added on both sides ceil_mode: When True, will use ceil instead of floor to compute the output shape count_include_pad: When True, will include the zero-padding in the averaging calculation

Returns

Output tensor of shape (N, C, D_out, H_out, W_out)