How Do Fully Connected Layers Work in CNN?
Visualize how a flattened 1D array of features connects to every node in the output layer using weights, biases, and Softmax to make final classifications.
Visualize how a flattened 1D array of features connects to every node in the output layer using weights, biases, and Softmax to make final classifications.
The decision-making powerhouse at the end of a Convolutional Neural Network.
Throughout the early stages of a CNN, images are processed as 2D grids (or 3D volumes with color channels). Convolutional and pooling layers extract spatial features like edges, textures, and shapes. However, to make a final classification (e.g., "Is this a cat or a dog?"), the network must flatten this 2D/3D data into a single 1D list of numbers. This is the input vector you see on the left.
It is called a Fully Connected (or Dense) layer because every single node in the input vector is connected to every single node in the output vector. If you have 4 inputs and 3 outputs, there are $4 \times 3 = 12$ distinct connections (weights), plus 3 biases.
Each weight represents the "importance" of a specific feature for a specific class. For example, if Input Feature 2 strongly represents "pointy ears", the weight connecting Input 2 to the "Cat" output node will likely be a high positive number, while its connection to "Bird" might be negative.
Click the Forward Pass button. Watch the center canvas. The network computes the output one node at a time. It highlights the connections, multiplies each input by its corresponding weight, sums them up, and adds a bias. This raw sum is called the Logit ($Z$).
Look at the Weights table on the right. Change the weights connecting to the "Cat" column to high positive numbers (e.g., 2.0). Click Forward Pass again. Notice how the raw score (Logit) for the Cat class shoots up!
At the bottom of the weights table are the Biases. A bias is an extra value added to the final sum. It shifts the activation function left or right. Try setting the Bird bias to a high value like 5.0. It will artificially inflate the Bird's probability regardless of the inputs.
Raw Logits can be any number (e.g., -5.2, 0.4, 12.8). To interpret them as probabilities, we apply the Softmax function. Softmax squashes the logits into values between 0 and 1, ensuring they all sum up to exactly 1.0 (or 100%). Notice how the progress bars in the Output section always balance each other out.
For an output node $j$, the raw Logit ($Z_j$) is the dot product of the inputs ($X$) and weights ($W$), plus bias ($b$):
Zj = (X1·W1j + X2·W2j + ...) + bj
Softmax is then applied to turn $Z$ into probabilities ($P$):
Pj = eZj / Σ(eZ)
Visualize how a flattened 1D array of features connects to every node in the output layer using weights, biases, and Softmax to make final classifications.