Answers.Body: <blockquote>
  <p>Do both the kernel values and weights in FCC get optimized?</p>
  </blockquote>
  <p>Yes.</p>
  <p>Some of the designs for image processing neural networks prior to CNNs had separate filter processing states. For instance, <a href="https://en.wikipedia.org/wiki/Sobel_operator" rel="nofollow noreferrer">Sobel filters</a> were popular choices in earlier attempts at machine learning on images, and they can be thought of as fixed CNN-like layers. They may still have a role in some projects.</p>
  <p>However, most CNN architectures for images now work with pixel data directly, and can learn both the filter weights and fully connected later weights together.</p>
  <p>In some uses, such as transfer learning, it is useful to be able to selectively learn only some of the layers. You may take the CNN filter layers from a very general image classifier trained on ImageNet, and repurpose it by replacing the fully connected layers. When training the new neural network you can freeze the filter layers and learn only the fully connected layers - although there is no specific requirement to separate them only by convolutional/fully-connected, you could equally retrain only part of the fully-connnected layers, or include some of the convolutional layers.</p>
  <blockquote>
  <p>If so, it seems like we're dealing with two different types of parameters. How are both trained simultaneously?</p>
  </blockquote>
  <p>They are not really that different. A CNN can be thought of as fully connected throughout, but with some extra constraints on the convolutional layers:</p>
  <ul>
  <li><p>Weights that would connect a feature map neuron to an input outside the bounds of the filter are always zero.</p>
  </li>
  <li><p>Weights for each position on the feature map are identical.</p>
  </li>
  </ul>
  <p>Using learnable convolution filters enforces both these constraints.</p>
  <p>The practical difference to how back propagation works in convolutional layers as opposed to fully connected layers is to sum all gradients arising from each &quot;pixel&quot; in the feature map to the appropriate filter weight when back propagating. So unlike a fully connected layer weight that receives one summed gradient update from the layer above, each convolutional filter weight receives the equivalent update summed over all pixels in the next feature layer. Depending on which source you learn CNNs from, this additional outer sum might be shown or might be implied using different notation for the update rules.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-24T07:59:11.577Z
Answers.LastActivityDate: 2021-06-25T07:09:48.743Z
Answers.LastEditDate: 2021-06-25T07:09:48.743Z
Answers.UserDisplayName: Neil Slater
Body: <p>In a convolutional neural network, the hyperparameters such as number of kernels and stride, kernel size, etc are determined. After some combination of convolutions, ReLU and pooling layer there is the fully connected (FC) layer in the end which yields a classification result. I originally thought that during training the values of kernels would be optimized and that kernels such as edge detection are a result of optimization.</p>
  <p>But at the end if we have weights to optimize at the FC layer, what is it that gets optimized during training of the CNN? Do both the kernel values and weights in FCC get optimized? If so, it seems like we're dealing with two different types of parameters. How are both trained simultaneously? If not so, are there simply sets of kernels known to work and automatically implemented in CNN modules?</p>
  
Tags: <neural-networks><convolutional-neural-networks><optimization><convolutional-layers><dense-layers>
Title: What gets optimized in convolutional neural network?
UserDisplayName: user48144
ThreadText: # What gets optimized in convolutional neural network?
  
  (Asked by: username_0 on 2021-06-24)
  
  In a convolutional neural network, the hyperparameters such as number of kernels and stride, kernel size, etc are determined. After some combination of convolutions, ReLU and pooling layer there is the fully connected (FC) layer in the end which yields a classification result. I originally thought that during training the values of kernels would be optimized and that kernels such as edge detection are a result of optimization.
  
  But at the end if we have weights to optimize at the FC layer, what is it that gets optimized during training of the CNN? Do both the kernel values and weights in FCC get optimized? If so, it seems like we're dealing with two different types of parameters. How are both trained simultaneously? If not so, are there simply sets of kernels known to work and automatically implemented in CNN modules?
  
  **Tags:** neural-networks, convolutional-neural-networks, optimization, convolutional-layers, dense-layers
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-24. Score: 3 | Accepted answer
  
  > Do both the kernel values and weights in FCC get optimized?
  
  Yes.
  
  Some of the designs for image processing neural networks prior to CNNs had separate filter processing states. For instance, [Sobel filters](https://en.wikipedia.org/wiki/Sobel_operator) were popular choices in earlier attempts at machine learning on images, and they can be thought of as fixed CNN-like layers. They may still have a role in some projects.
  
  However, most CNN architectures for images now work with pixel data directly, and can learn both the filter weights and fully connected later weights together.
  
  In some uses, such as transfer learning, it is useful to be able to selectively learn only some of the layers. You may take the CNN filter layers from a very general image classifier trained on ImageNet, and repurpose it by replacing the fully connected layers. When training the new neural network you can freeze the filter layers and learn only the fully connected layers - although there is no specific requirement to separate them only by convolutional/fully-connected, you could equally retrain only part of the fully-connnected layers, or include some of the convolutional layers.
  
  > If so, it seems like we're dealing with two different types of parameters. How are both trained simultaneously?
  
  They are not really that different. A CNN can be thought of as fully connected throughout, but with some extra constraints on the convolutional layers:
  
  * Weights that would connect a feature map neuron to an input outside the bounds of the filter are always zero.
  * Weights for each position on the feature map are identical.
  
  Using learnable convolution filters enforces both these constraints.
  
  The practical difference to how back propagation works in convolutional layers as opposed to fully connected layers is to sum all gradients arising from each "pixel" in the feature map to the appropriate filter weight when back propagating. So unlike a fully connected layer weight that receives one summed gradient update from the layer above, each convolutional filter weight receives the equivalent update summed over all pixels in the next feature layer. Depending on which source you learn CNNs from, this additional outer sum might be shown or might be implied using different notation for the update rules.
  
  
  ---
  
  