What do the fully connected layers do in CNNs? I understand the convolutional and pooling layers, but I cannot see the reason for a fully connected layer in CNNs. Why isn't the previous layer directly connected to the output layer?
 A: I found this answer by  Anil-Sharma on Quora helpful.
We can divide the whole network (for classification) into two parts:


*

*Feature extraction:
In the conventional classification algorithms, like SVMs, we used to extract features from the data to make the classification work. The convolutional layers are serving the same purpose of feature extraction. CNNs capture better representation of data and hence we don’t need to do feature engineering. 

*Classification:
After feature extraction we need to classify the data into various classes, this can be done using a fully connected (FC) neural network. In place of fully connected layers, we can also use a conventional classifier like SVM. But we generally end up adding FC layers to make the model end-to-end trainable.
A: The output from the convolutional layers represents high-level features in the data.  While that output could be flattened and connected to the output layer, adding a fully-connected layer is a (usually) cheap way of learning non-linear combinations of these features.
Essentially the convolutional layers are providing a meaningful, low-dimensional, and somewhat invariant feature space, and the fully-connected layer is learning a (possibly non-linear) function in that space.
NOTE:
It is trivial to convert from FC layers to Conv layers. Converting these top FC layers to Conv layers can be helpful as this page describes.
