DL0011 Fully Connected Layer

Can you explain what a fully connected layer is?

Answer

A fully connected (FC) layer, also called a dense layer, is a layer in which every neuron connects to all neurons of the previous layer. It computes a weighted sum of its inputs, adds a bias, and applies an activation function, letting the network learn global combinations of features. FC layers typically appear at the end of a network, mapping extracted features to class scores.

(1) Dense Connectivity: With n_{in} inputs and n_{out} neurons, the layer holds n_{in} \times n_{out} weights plus n_{out} biases.
(2) Parameter Heavy: FC layers often dominate model size (e.g., flattening a 7 \times 7 \times 512 map into 1000 classes needs ~25M parameters), which raises overfitting risk.
(3) Loses Spatial Structure: Inputs must be flattened, discarding spatial layout; Global Average Pooling (GAP) is a parameter-free alternative.

Mathematical Formulation:
y = \sigma(Wx + b)
\#\text{params} = (n_{in} + 1) \times n_{out}

Where:

  • x \in \mathbb{R}^{n_{in}} is the flattened input vector and y \in \mathbb{R}^{n_{out}} is the output vector.
  • W \in \mathbb{R}^{n_{out} \times n_{in}} is the weight matrix and b \in \mathbb{R}^{n_{out}} is the bias vector.
  • \sigma is a non-linear activation such as ReLU (or softmax at the classifier output).
Fully connected layer diagram showing every input neuron connected to every output neuron, with the weighted sum and activation annotation.

Figure 1: In an FC layer, every input neuron connects to every output neuron; each output is \sigma(\sum_j w_j x_j + b).

Flatten + FC vs GAP + FC: For a CNN head with 7 \times 7 \times 8 feature maps and 6 classes, flattening feeds 392 values to the FC layer, while GAP feeds only 8, a 44× parameter reduction with less overfitting:

ApproachFC Input SizeFC ParametersSpatial Info
Flatten + FC7 \times 7 \times 8 = 392(392 + 1) \times 6 = 2358Discarded by flattening
GAP + FC8 (one per channel)(8 + 1) \times 6 = 54Summarized per channel
Two CNN head pipelines compared: flatten plus fully connected layer versus global average pooling plus fully connected layer, with parameter counts annotated.

Figure 2: GAP collapses each feature map to one value before the FC layer, cutting parameters from 2358 to 54 in this example.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *