Answers.Body: <p>The reason is that when using a convolutional layer, you select the size of the <em>filter kernels</em>, which are independent of the image/layer input size (provided that images smaller than the kernels are padded appropriately).</p>
  
  <p>When using a dense layer, you specify the size of the layer itself and the resulting weight matrix is a function of both the size of the dense layer and the upstream layer. This is because each neuron in the upstream layer makes a connection to each neuron in the dense layer. So, if you have 50 neurons in the upstream layer and 20 neurons in the dense layer, then the weight matrix has <span class="math-container">$50 \times 20=1000$</span> values. Those weights are what get determined during the training phase, and so those layer sizes are fixed.</p>
  
  <p>Now, the output of a CNN layer is a number of images/tensors (specified by the number of filters chosen), whose size is determined by the kernel size and any padding option chosen. If those are fed into a dense layer, then that fixes the the size that those images can be (because of the reason given in the previous paragraph). </p>
  
  <p>On the other hand, if no dense layer is used in the whole network, then the input to the first CNN layer can be any size because the weights are just the individual parameters of the filter kernels, and the filter kernels remain the same size regardless of the input tensor size.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-20T22:08:57.807Z
Answers.Text: If you feed a FCN (fully convolutional network) with a input of size $50\times 50$ and $300 \times 300$, although you have no problem processing with convolutions and pooling layers, how you output class score since the output size of convolutional layers depends on the size of their input?
Answers.UserDisplayName: Antonios Sarikas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-27T09:55:56.757Z
Answers.LastActivityDate: 2020-06-14T10:59:44.273Z
Answers.LastEditDate: 2020-06-14T10:59:44.273Z
Answers.UserDisplayName: DrMcCleod
Body: <p>On <a href="https://towardsdatascience.com/understanding-semantic-segmentation-with-unet-6be4f42d4b47" rel="nofollow noreferrer">this</a> article, it says that: </p>
  
  <blockquote>
    <p>The UNET was developed by Olaf Ronneberger et al. for Bio Medical Image Segmentation. The architecture contains two paths. First path is the contraction path (also called as the encoder) which is used to capture the context in the image. The encoder is just a traditional stack of convolutional and max pooling layers. The second path is the symmetric expanding path (also called as the decoder) which is used to enable precise localization using transposed convolutions. Thus it is an end-to-end fully convolutional network (FCN), i.e. it only contains Convolutional layers and does not contain any Dense layer because of which it can accept image of any size.</p>
  </blockquote>
  
  <p>What I don't understand is how an FCN can accept images of any size, while an ordinary object detector, such as YOLO with a dense layer at the very end, cannot accept images of any size. </p>
  
  <p>So, why can a fully convolutional network accept images of any size?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-06-27T09:30:02.037Z
Comments.Text: Because it don't have dense layers obviously. Convolutional layer work for any input size (more then kernel size)
Comments.UserDisplayName: mirror2image
Tags: <neural-networks><deep-learning><convolutional-neural-networks><fully-convolutional-networks>
Title: Why can a fully convolutional network accept images of any size?
UserDisplayName: SDG
ThreadText: # Why can a fully convolutional network accept images of any size?
  
  (Asked by: username_0 on 2019-06-27)
  
  On [this](https://towardsdatascience.com/understanding-semantic-segmentation-with-unet-6be4f42d4b47) article, it says that:
  
  > The UNET was developed by Olaf Ronneberger et al. for Bio Medical Image Segmentation. The architecture contains two paths. First path is the contraction path (also called as the encoder) which is used to capture the context in the image. The encoder is just a traditional stack of convolutional and max pooling layers. The second path is the symmetric expanding path (also called as the decoder) which is used to enable precise localization using transposed convolutions. Thus it is an end-to-end fully convolutional network (FCN), i.e. it only contains Convolutional layers and does not contain any Dense layer because of which it can accept image of any size.
  
  What I don't understand is how an FCN can accept images of any size, while an ordinary object detector, such as YOLO with a dense layer at the very end, cannot accept images of any size.
  
  So, why can a fully convolutional network accept images of any size?
  
  **Tags:** neural-networks, deep-learning, convolutional-neural-networks, fully-convolutional-networks
  
  > **Comments:**
  > **username_1**: Because it don't have dense layers obviously. Convolutional layer work for any input size (more then kernel size)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-06-27. Score: 8 | Accepted answer
  
  The reason is that when using a convolutional layer, you select the size of the *filter kernels*, which are independent of the image/layer input size (provided that images smaller than the kernels are padded appropriately).
  
  When using a dense layer, you specify the size of the layer itself and the resulting weight matrix is a function of both the size of the dense layer and the upstream layer. This is because each neuron in the upstream layer makes a connection to each neuron in the dense layer. So, if you have 50 neurons in the upstream layer and 20 neurons in the dense layer, then the weight matrix has $50 \times 20=1000$ values. Those weights are what get determined during the training phase, and so those layer sizes are fixed.
  
  Now, the output of a CNN layer is a number of images/tensors (specified by the number of filters chosen), whose size is determined by the kernel size and any padding option chosen. If those are fed into a dense layer, then that fixes the the size that those images can be (because of the reason given in the previous paragraph).
  
  On the other hand, if no dense layer is used in the whole network, then the input to the first CNN layer can be any size because the weights are just the individual parameters of the filter kernels, and the filter kernels remain the same size regardless of the input tensor size.
  
  > **Comments:**
  > **username_3**: If you feed a FCN (fully convolutional network) with a input of size $50\times 50$ and $300 \times 300$, although you have no problem processing with convolutions and pooling layers, how you output class score since the output size of convolutional layers depends on the size of their input?  
  
  ---
  
  