DilatedConv2d

class DilatedConv2d<T : DType, V>(val inChannels: Int, val outChannels: Int, val kernelSize: Pair<Int, Int>, val dilation: Pair<Int, Int>, val stride: Pair<Int, Int> = 1 to 1, val padding: Pair<Int, Int> = 0 to 0, val groups: Int = 1, val bias: Boolean = true, val name: String = "DilatedConv2d", initWeights: Tensor<T, V>, initBias: Tensor<T, V>? = null) : Module<T, V> , ModuleParameters<T, V> (source)

Dilated (Atrous) Convolution layer.

Dilated convolution introduces gaps (holes) between the kernel elements, effectively increasing the receptive field without increasing the number of parameters or computational cost. This is particularly useful for semantic segmentation and other tasks where capturing multi-scale context is important.

The dilation parameter controls the spacing between kernel elements:

  • dilation = (1, 1): standard convolution

  • dilation = (2, 2): skip every other pixel

  • dilation = (4, 4): skip every 4th pixel

Dilated convolution is also known as "atrous convolution" (from the French word "à trous" meaning "with holes").

This is essentially a convenience wrapper around Conv2d with explicit dilation handling and additional utility methods for dilated convolution operations.

Parameters

inChannels

Number of input channels

outChannels

Number of output channels/filters

kernelSize

Size of the convolving kernel (height, width)

dilation

Spacing between kernel elements (dilation rate)

stride

Stride of the convolution (default: 1, 1)

padding

Padding added to all sides of the input (default: 0, 0)

groups

Number of groups for grouped dilated convolution (default: 1)

bias

Whether to add a learnable bias to the output (default: true)

name

Name of the module

initWeights

Initial weights tensor

initBias

Initial bias tensor (if bias is true)

Constructors

Link copied to clipboard
constructor(inChannels: Int, outChannels: Int, kernelSize: Pair<Int, Int>, dilation: Pair<Int, Int>, stride: Pair<Int, Int> = 1 to 1, padding: Pair<Int, Int> = 0 to 0, groups: Int = 1, bias: Boolean = true, name: String = "DilatedConv2d", initWeights: Tensor<T, V>, initBias: Tensor<T, V>? = null)

Types

Link copied to clipboard
object Companion

Creates a multi-scale dilated convolution block with different dilation rates. This is commonly used in semantic segmentation (e.g., DeepLab's ASPP).

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val groups: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val modules: List<Module<T, V>>
Link copied to clipboard
open override val name: String
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val params: List<ModuleParameter<T, V>>

Parameters owned by this node (weights, biases, etc.).

Link copied to clipboard

Functions

Link copied to clipboard

Returns information about the dilated convolution configuration.

Link copied to clipboard

Returns the effective kernel size considering dilation. This is the size of the receptive field that the dilated kernel covers.

Link copied to clipboard
open override fun forward(input: Tensor<T, V>, ctx: ExecutionContext): Tensor<T, V>
Link copied to clipboard

Checks if this is a standard convolution (dilation == (1, 1)).

Link copied to clipboard
fun outputSize(inputSize: Pair<Int, Int>): Pair<Int, Int>

Calculates the output size for a given input size.

Link copied to clipboard

Returns the total number of parameters in this layer. Dilation doesn't change the parameter count compared to standard convolution.

Link copied to clipboard

Returns the receptive field expansion ratio compared to standard convolution. This shows how much larger the receptive field is due to dilation.

Link copied to clipboard

Returns the receptive field size at the input level. This shows how much of the input each output pixel can "see".