6
$\begingroup$

I have implemented a CNN for image classification. I have not used fully connected layers, but only a softmax. Still, I am getting results.

Must I use fully-connected layers in a CNN?

$\endgroup$
1
  • 1
    $\begingroup$ Depends on what you want to do. If you want to classify images, FC is simply a convenient way of making all the outputs of the previous layer contribute to the final classification. Convolutional layers on the other hand, have a sparser connectivity, so you can't use them. However FC layers aren't the only way to classify the features extracted by the CNN. I've seen other classifiers being used besides FC as well. That being said there are many tasks, besides classification, where CNNs are used without FC layers. One example is image segmentation. $\endgroup$
    – Djib2011
    Aug 7, 2019 at 9:47

3 Answers 3

3
$\begingroup$

Are fully connected layers necessary in a CNN?

No. In fact, you can simulate a fully connected layer with convolutions. A convolutional neural network (CNN) that does not have fully connected layers is called a fully convolutional network (FCN). See this answer for more info.

An example of an FCN is the u-net, which does not use any fully connected layers, but only convolution, downsampling (i.e. pooling), upsampling (deconvolution), and copy and crop operations. Nevertheless, u-net is used to classify pixels (more precisely, semantic segmentation).

Moreover, you can use CNNs only for the purpose of feature extraction, and then feed these extracted features in another classifier (e.g. an SVM). In fact, transfer learning is based on the idea that CNNs extract reusable features.

$\endgroup$
2
  • 1
    $\begingroup$ as an extension to this answer, see cs231n.github.io/convolutional-networks/#convert for exactly how to write a FC layer as a Conv and vice versa. $\endgroup$
    – Gulzar
    Jan 21, 2021 at 17:22
  • $\begingroup$ Could you elaborate or point to a nice, brief explanation on how CNNs are used to extract features? $\endgroup$
    – mesllo
    Feb 11, 2022 at 18:43
1
$\begingroup$

The reasons people use the FC after convolutional layer is that CNN preserves spatial information. You said you use softmax, so you probably make some classification task. If you don't use FC layer, then you probably evaluate first class by first position of the first kernel, not by whole image with all kernels, second class by second position of the kernel and so on.

The dense net combine the info from all the kernels in all positions.

That said, you technically can convert FC to Conv net, as described here, so then you can said you "skipped" FC layer.

$\endgroup$
1
$\begingroup$

In theory, you do not need fully-connected (FC) layers. FC layers are used to introduce scope for updating weights during back-propagation, due to its ability to introduce more connectivity possibilities, as every neuron of the FC is connected every neuron of the further layers.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .