GroupedConv2d

class GroupedConv2d<T : DType, V>(val inChannels: Int, val outChannels: Int, val kernelSize: Pair<Int, Int>, val groups: 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 = "GroupedConv2d", initWeights: Tensor<T, V>, initBias: Tensor<T, V>? = null) : Module<T, V> , ModuleParameters<T, V> (source)

Grouped Convolution layer.

In grouped convolution, the input channels are divided into groups, and each group is convolved separately with its own set of filters. This reduces the number of parameters and computational complexity while potentially improving feature learning by encouraging different groups to learn different types of features.

When groups = 1, this is equivalent to standard convolution. When groups = inChannels, this is equivalent to depthwise convolution.

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

Parameters

inChannels

Number of input channels

outChannels

Number of output channels/filters

kernelSize

Size of the convolving kernel (height, width)

groups

Number of groups to divide channels into

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 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>, groups: 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 = "GroupedConv2d", initWeights: Tensor<T, V>, initBias: Tensor<T, V>? = null)

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 the computational complexity reduction ratio compared to standard convolution. This is the same as parameter reduction for convolution operations.

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

Returns information about the grouped convolution configuration.

Link copied to clipboard

Returns the number of input channels per group.

Link copied to clipboard

Checks if this is a depthwise convolution (groups == inChannels).

Link copied to clipboard

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

Link copied to clipboard

Returns the number of output channels per group.

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.

Link copied to clipboard

Returns the parameter reduction ratio compared to a standard convolution (groups = 1).