TransposedConv2d

class TransposedConv2d<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 outputPadding: Pair<Int, Int> = 0 to 0, val dilation: Pair<Int, Int> = 1 to 1, val groups: Int = 1, val bias: Boolean = true, val name: String = "TransposedConv2d", initWeights: Tensor<T, V>, initBias: Tensor<T, V>? = null) : Module<T, V> , ModuleParameters<T, V> (source)

Transposed Convolution (Deconvolution) layer.

Transposed convolution is used for upsampling, essentially performing the reverse operation of convolution. It's commonly used in:

  • Generative models (GANs, VAEs)

  • Semantic segmentation (decoder networks)

  • Super-resolution networks

  • Any architecture requiring learned upsampling

Despite sometimes being called "deconvolution", it doesn't truly invert the convolution operation, but rather learns an upsampling transformation.

The transposed convolution increases the spatial dimensions of the input, making it useful for tasks that need to go from low-resolution feature maps to higher-resolution outputs.

Parameters

inChannels

Number of input channels

outChannels

Number of output channels/filters

kernelSize

Size of the convolving kernel (height, width)

stride

Stride of the transposed convolution (default: 1, 1)

padding

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

outputPadding

Additional padding added to one side of output shape (default: 0, 0)

dilation

Spacing between kernel elements (default: 1, 1)

groups

Number of groups for grouped transposed 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>, stride: Pair<Int, Int> = 1 to 1, padding: Pair<Int, Int> = 0 to 0, outputPadding: Pair<Int, Int> = 0 to 0, dilation: Pair<Int, Int> = 1 to 1, groups: Int = 1, bias: Boolean = true, name: String = "TransposedConv2d", initWeights: Tensor<T, V>, initBias: Tensor<T, V>? = null)

Types

Link copied to clipboard
object Companion

Factory methods for common transposed convolution configurations.

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
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

Checks if this is a simple 2x upsampling (stride == (2, 2)).

Link copied to clipboard

Checks if this is a standard transposed convolution (no dilation, no groups).

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

Calculates the output size for a given input size and transposed convolution parameters.

Link copied to clipboard

Returns the total number of parameters in this layer.

Link copied to clipboard

Returns information about the transposed convolution configuration.

Link copied to clipboard

Returns the upsampling factor based on stride.