<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSCNNFullyConnected",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSCNNFullyConnected"
  },
  "title" : "MPSCNNFullyConnected"
}
-->

# MPSCNNFullyConnected

A fully connected convolution layer, also known as an inner product layer.

```
class MPSCNNFullyConnected
```

## Overview

A fully connected layer in  a Convolutional Neural Network (CNN) is one where every input channel is connected to every output channel. The kernel width is equal to the width of the source image, and the kernel height is equal to the height of the source image. The width and height of the output is `1 x 1`.

A fully connected layer takes an [`MPSImage`](/documentation/MetalPerformanceShaders/MPSImage) object with dimensions `source.width x source.height x Ni`, convolves it with `Weights[No][source.width][source.height][Ni]`,` `and produces a `1 x 1 x No` output.

Thus, the following conditions must be true:

- `kernelWidth  == source.width`
- `kernelHeight == source.height`
- `clipRect.size.width == 1`
- `clipRect.size.height == 1`

You can think of a fully connected layer as a matrix multiplication where the image is flattened into a vector of length `source.width*source.height*Ni`, and the weights are arranged in a matrix of dimension `No x (source.width*source.height*Ni)` to produce an output vector of length `No`.

The value of the `strideInPixelsX`, [`strideInPixelsY`](/documentation/MetalPerformanceShaders/MPSCNNConvolutionDescriptor/strideInPixelsY), and [`groups`](/documentation/MetalPerformanceShaders/MPSCNNConvolution/groups) properties must be `1`. The [`offset`](/documentation/MetalPerformanceShaders/MPSCNNKernel/offset) property is not applicable and it is ignored. Because the clip rectangle is clamped to the destination image bounds, if the destination is `1 x 1`, you do not need to set the [`clipRect`](/documentation/MetalPerformanceShaders/MPSCNNKernel/clipRect) property.

> Note:
> You can implement a fully connected convolution layer using an ``doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNConvolution`` object by setting the following property values:
> 
> `offset = (kernelWidth/2,kernelHeight/2)`
> 
> `clipRect.origin = (ox,oy)`
> 
> `clipRect.size = (1,1)`
> 
> `strideInPixelsX = strideInPixelsY = groups = 1`
> 
> However, using an ``doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNFullyConnected`` object directly is better for performance as it lets the Metal Performance Shaders framework choose the most performant implementation method, which may not be possible when you use a general convolution. For example, the framework may internally use matrix multiplication or special reduction kernels for a specific Metal feature set.

## Topics

### Initializers

[`init(coder:device:)`](/documentation/MetalPerformanceShaders/MPSCNNFullyConnected/init(coder:device:))

Initializes a fully connected convolution layer.

[`init(device:weights:)`](/documentation/MetalPerformanceShaders/MPSCNNFullyConnected/init(device:weights:))

Initializes a fully connected convolution layer.

[`MPSCNNConvolutionDataSource`](/documentation/MetalPerformanceShaders/MPSCNNConvolutionDataSource)

The protocol that provides convolution filter weights and bias terms.

[`init(device:convolutionDescriptor:kernelWeights:biasTerms:flags:)`](/documentation/MetalPerformanceShaders/MPSCNNFullyConnected/init(device:convolutionDescriptor:kernelWeights:biasTerms:flags:))

Initializes a fully connected convolution layer.

[`MPSCNNConvolutionDescriptor`](/documentation/MetalPerformanceShaders/MPSCNNConvolutionDescriptor)

A description of the attributes of a convolution kernel.

[`MPSCNNConvolutionFlags`](/documentation/MetalPerformanceShaders/MPSCNNConvolutionFlags)

Options used to control how kernel weights are stored and used in the CNN kernels



---

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)