espnet2.enh.layers.conv_utils.conv2d_output_shape
Less than 1 minute
espnet2.enh.layers.conv_utils.conv2d_output_shape
espnet2.enh.layers.conv_utils.conv2d_output_shape(h_w, kernel_size=1, stride=1, pad=0, dilation=1)
Calculate the output shape of a 2D convolution layer.
This function computes the height and width of the output tensor resulting from a 2D convolution operation based on the input dimensions, kernel size, stride, padding, and dilation. The function can handle both single integers and tuples for the parameters.
- Parameters:
- h_w (Union *[*int , tuple ]) – The height and width of the input tensor.
- kernel_size (Union *[*int , tuple ] , optional) – The size of the kernel. Default is 1.
- stride (Union *[*int , tuple ] , optional) – The stride of the convolution. Default is 1.
- pad (Union *[*int , tuple ] , optional) – The padding applied to the input. Default is 0.
- dilation (Union *[*int , tuple ] , optional) – The dilation factor for the kernel. Default is 1.
- Returns: A tuple containing the height and width of the output tensor.
- Return type: tuple
Examples
>>> conv2d_output_shape((32, 32), kernel_size=3, stride=1, pad=1)
(32, 32)
>>> conv2d_output_shape((32, 32), kernel_size=3, stride=2, pad=1)
(16, 16)
NOTE
The input dimensions (h_w) should be provided as a tuple (height, width) or as a single integer if both dimensions are the same.