DepthwiseSeparableConv2d

class DepthwiseSeparableConv2d<T : DType, V>(val inChannels: Int, val outChannels: Int, val kernelSize: Pair<Int, Int>, val stride: Pair<Int, Int> = 1 to 1, val padding: Pair<Int, Int> = 0 to 0, val dilation: Pair<Int, Int> = 1 to 1, val bias: Boolean = true, val name: String = "DepthwiseSeparableConv2d", initDepthwiseWeights: Tensor<T, V>, initPointwiseWeights: Tensor<T, V>, initDepthwiseBias: Tensor<T, V>? = null, initPointwiseBias: Tensor<T, V>? = null) : Module<T, V> , ModuleParameters<T, V> (source)

Depthwise Separable Convolution layer.

This layer applies a depthwise convolution followed by a pointwise convolution. It's more efficient than standard convolution as it reduces the number of parameters and computational complexity while maintaining similar representational power.

The operation is split into two parts:

  1. Depthwise convolution: applies a single filter per input channel (groups = inChannels)

  2. Pointwise convolution: 1x1 convolution to combine the depthwise outputs

Parameters

inChannels

Number of input channels

outChannels

Number of output channels/filters

kernelSize

Size of the convolving kernel for depthwise convolution (height, width)

stride

Stride of the convolution (default: 1, 1)

padding

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

dilation

Spacing between kernel elements (default: 1, 1)

bias

Whether to add learnable bias to both depthwise and pointwise layers (default: true)

name

Name of the module

initDepthwiseWeights

Initial weights for depthwise convolution

initPointwiseWeights

Initial weights for pointwise convolution

initDepthwiseBias

Initial bias for depthwise convolution (if bias is true)

initPointwiseBias

Initial bias for pointwise convolution (if bias is true)

Constructors

Link copied to clipboard
constructor(inChannels: Int, outChannels: Int, kernelSize: Pair<Int, Int>, stride: Pair<Int, Int> = 1 to 1, padding: Pair<Int, Int> = 0 to 0, dilation: Pair<Int, Int> = 1 to 1, bias: Boolean = true, name: String = "DepthwiseSeparableConv2d", initDepthwiseWeights: Tensor<T, V>, initPointwiseWeights: Tensor<T, V>, initDepthwiseBias: Tensor<T, V>? = null, initPointwiseBias: Tensor<T, V>? = null)

Properties

Link copied to clipboard
Link copied to clipboard
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
open override fun forward(input: Tensor<T, V>, ctx: ExecutionContext): Tensor<T, V>
Link copied to clipboard
fun outputSize(inputSize: Pair<Int, Int>): Pair<Int, Int>

Calculates the output size for the entire depthwise separable convolution. The output size is determined by the depthwise convolution since pointwise uses 1x1 kernels.

Link copied to clipboard

Returns the total number of parameters in this layer. This is typically much less than a standard convolution with the same input/output dimensions.

Link copied to clipboard

Returns the parameter reduction ratio compared to a standard convolution.