Answers.Body: <blockquote>
    <p>Are fully connected layers necessary in a CNN?</p>
  </blockquote>
  
  <p>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 <strong>fully convolutional network (FCN)</strong>. See <a href="https://ai.stackexchange.com/a/21824/2444">this answer</a> for more info.</p>
  
  <p>An example of an FCN is the <a href="https://arxiv.org/abs/1505.04597" rel="nofollow noreferrer">u-net</a>, which does <em>not</em> 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).</p>
  
  <p>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 <em>reusable</em> features.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-21T17:22:00.343Z
Answers.Text: as an extension to this answer, see https://cs231n.github.io/convolutional-networks/#convert for exactly how to write a FC layer as a Conv and vice versa.
Answers.UserDisplayName: Gulzar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-11T18:43:32.567Z
Answers.Text: Could you elaborate or point to a nice, brief explanation on how CNNs are used to extract features?
Answers.UserDisplayName: mesllo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-12T15:56:14.047Z
Answers.LastActivityDate: 2020-06-12T16:03:06.430Z
Answers.LastEditDate: 2020-06-12T16:03:06.430Z
Answers.UserDisplayName: nbro
Answers.Body: <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T14:41:46.437Z
Answers.LastActivityDate: 2019-08-06T22:38:15.707Z
Answers.LastEditDate: 2019-08-06T22:38:15.707Z
Answers.UserDisplayName: Srikant Jayaraman
Answers.Body: <p>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.</p>
  
  <p>The dense net combine the info from all the kernels in all positions.</p>
  
  <p>That said, you technically can convert FC to Conv net, as <a href="http://cs231n.github.io/convolutional-networks/#convert" rel="nofollow noreferrer">described here</a>, so then you can said you "skipped" FC layer.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T14:42:41.743Z
Answers.LastActivityDate: 2019-08-06T14:42:41.743Z
Answers.UserDisplayName: Kirill Fedyanin
Answers.Body: <p>There are mainly two main reasons for which we use FCN:</p>
  <ol>
  <li><p>If we use a fully connected layer for any classification or regression task, we have to flatten the results before transferring the information into the fully connected layer, which will result in the loss of spatial information.</p>
  </li>
  <li><p>Usually, the parameter cost of using a fully connected layer is high as compared to convolution layers.</p>
  </li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-20T13:01:46.070Z
Answers.LastActivityDate: 2024-04-20T13:01:46.070Z
Answers.UserDisplayName: Srajan
Body: <p>I have implemented a CNN for image classification. I have not used fully connected layers, but only a softmax. Still, I am getting results. </p>
  
  <p>Must I use fully-connected layers in a CNN?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-07T09:47:13.983Z
Comments.Text: 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.
Comments.UserDisplayName: Djib2011
Tags: <neural-networks><deep-learning><convolutional-neural-networks>
Title: Are fully connected layers necessary in a CNN?
UserDisplayName: SARIKA
ThreadText: # Are fully connected layers necessary in a CNN?
  
  (Asked by: username_0 on 2019-08-06)
  
  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?
  
  **Tags:** neural-networks, deep-learning, convolutional-neural-networks
  > **Comments:**
  > **username_1**: 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.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2020-06-12. Score: 4
  
  > 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](https://ai.stackexchange.com/a/21824/2444) for more info.
  
  An example of an FCN is the [u-net](https://arxiv.org/abs/1505.04597), 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.
  
  > **Comments:**
  > **username_3**: as an extension to this answer, see https://cs231n.github.io/convolutional-networks/#convert for exactly how to write a FC layer as a Conv and vice versa.  
  > **username_4**: Could you elaborate or point to a nice, brief explanation on how CNNs are used to extract features?  
  
  ---
  
  ### Answer by username_5 on 2019-08-06. Score: 1
  
  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.
  
  
  ---
  
  ### Answer by username_6 on 2019-08-06. Score: 1
  
  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](http://cs231n.github.io/convolutional-networks/#convert), so then you can said you "skipped" FC layer.
  
  
  ---
  
  ### Answer by username_7 on 2024-04-20. Score: 0
  
  There are mainly two main reasons for which we use FCN:
  
  1. If we use a fully connected layer for any classification or regression task, we have to flatten the results before transferring the information into the fully connected layer, which will result in the loss of spatial information.
  2. Usually, the parameter cost of using a fully connected layer is high as compared to convolution layers.
  
  
  ---
  
  