<!--
{
  "availability" : [
    "iOS: 14.0.0 - 18.0.0",
    "iPadOS: 14.0.0 - 18.0.0",
    "macCatalyst: 14.0.0 - 18.0.0",
    "macOS: 11.0.0 - 15.0.0",
    "tvOS: 14.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0",
    "watchOS: 7.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSFilterCreateLayerTransposedConvolution(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSFilterCreateLayerTransposedConvolution"
  },
  "title" : "BNNSFilterCreateLayerTransposedConvolution(_:_:)"
}
-->

# BNNSFilterCreateLayerTransposedConvolution(_:_:)

Returns a new transposed convolution layer.

```
func BNNSFilterCreateLayerTransposedConvolution(_ layer_params: UnsafePointer<BNNSLayerParametersConvolution>, _ filter_params: UnsafePointer<BNNSFilterParameters>?) -> BNNSFilter?
```

## Parameters

`layer_params`

Layer parameters.

`filter_params`

The filter runtime parameters.

## Discussion

Use transposed convolution to upsample a tensor by performing an operation that’s effectively the inverse of a convolution.

The following figure illustrates the process of transposed convolution. The operation multiplies each element in the input by the kernel to produce the corresponding values in the output. The final output, pictured at the bottom of the figure, is the sum of the products:

![Figure that describes a transposed convolution operation over a two times two source matrix using a three times three kernel. Each step is illustrated as a row, showing scalar multiplication of the source element multiplied by the kernel, and the transposed convolution result is the sum of each scalar multiplication.](images/com.apple.accelerate/media-3633105@2x.png)

Use the following code to perform the illustrated transposed convolution:

```swift
let input = [Float](repeating: 1, count: 2 * 2)

var kernel = [Float](repeating: 1, count: 3 * 3)

var output = [Float](repeating: 0, count: 4 * 4)

kernel.withUnsafeMutableBufferPointer { kernelPtr in
    
    let inDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                             layout: BNNSDataLayoutImageCHW,
                                             size: (2, 2, 1, 0, 0, 0, 0, 0),
                                             stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                             data: nil,
                                             data_type: .float,
                                             table_data: nil,
                                             table_data_type: .float,
                                             data_scale: 1,
                                             data_bias: 0)
    
    let weightsDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                  layout: BNNSDataLayoutConvolutionWeightsOIHW,
                                                  size: (3, 3, 1, 1, 0, 0, 0, 0),
                                                  stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                                  data: kernelPtr.baseAddress,
                                                  data_type: .float,
                                                  table_data: nil,
                                                  table_data_type: .float,
                                                  data_scale: 1,
                                                  data_bias: 0)
    
    let outDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                              layout: BNNSDataLayoutImageCHW,
                                              size: (4, 4, 1, 0, 0, 0, 0, 0),
                                              stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                              data: nil,
                                              data_type: .float,
                                              table_data: nil,
                                              table_data_type: .float,
                                              data_scale: 1,
                                              data_bias: 0)
    
    var parameters = BNNSLayerParametersConvolution(i_desc: inDescriptor,
                                                    w_desc: weightsDescriptor,
                                                    o_desc: outDescriptor,
                                                    bias: BNNSNDArrayDescriptor(),
                                                    activation: .identity,
                                                    x_stride: 1, y_stride: 1,
                                                    x_dilation_stride: 0, y_dilation_stride: 0,
                                                    x_padding: 0, y_padding: 0,
                                                    groups: 1,
                                                    pad: (0, 0, 0, 0))

    let filter = BNNSFilterCreateLayerTransposedConvolution(&parameters,
                                                            nil)
    defer {
        BNNSFilterDestroy(filter)
    }
    
    BNNSFilterApply(filter,
                    input,
                    &output)
}
```

On return, `output` contains the following values:

```swift
[ 1.0, 2.0, 2.0, 1.0, 
  2.0, 4.0, 4.0, 2.0, 
  2.0, 4.0, 4.0, 2.0, 
  1.0, 2.0, 2.0, 1.0 ]
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)