# A Survey of Convolutional Neural Networks on Edge with Reconfigurable Computing
## 2 Convolutional Neural Networks
### CNN Layers  
The convolutional layer receives a set of input feature maps (IFM) and generates a set of output feature maps (OFM). A feature map is a 2D matrix of neurons and several feature maps form a 3D volume of feature maps (see Figure 2). Figure 2: Input and output feature maps of a convolutional layer. A single 3D block of weights, kernel, is convoluted across the input feature maps and computes an output feature map. Several kernels are applied to the input feature maps producing each single new output feature map. The number of output feature maps is therefore the same as the number of kernels. To explore spatial local correlation between adjacent neurons, the convolution window (width \(\times\) weight) of kernels is usually small (e.g., 3 \(\times\) 3, 5 \(\times\) 5). Usually, kernels slide across the feature maps, shifting one neuron each time (stride of 1). This generates high overlapping that increases with the window size and output feature maps with the same size. Instead, a larger stride can be used, resulting in less overlap and a smaller output volume. Strides higher than one are usually used in the initial layers. IFMs can be extended with additional neurons at the borders, known as padding, to generate output feature maps with the same size of input feature maps. To preserve the size of the feature maps, zeros are usually added at the border of the map. The number of weights of a convolutional layer, \(NW_{CL}\), depends on the number of kernels, \(nk\), and the size of the kernels, \((kx,ky,kz)\), and is given by:  
\[NW_{CL}=nk\times(kx\times ky\times kz+1)\]  
The number of multiply-accumulations (MACC), \(MACC_{CL}\), depends on the size of the input feature maps, \((wx,wy,wz)\), the size of the kernels, and the number of kernels as follows:  
\[MACC_{CL}=2\times nk\times(kx\times ky\times kz+1)\times(wx\times wz)\]  
The number of weights determines the memory size required to store the weights and the number of operations determines the computational complexity of the convolution. The pooling layer subsamples the IFMs to achieve translation invariance and reduce over-fitting. Basically, the relative location of a feature is more important than its absolute location. Given an input image and the size of the pooling window (typically \(2\times 2\) or \(3\times 3\)), a pooling function is applied to the neurons within the pooling window (see Figure 3). The most-used pooling functions are average pooling (calculates the average among the output neurons within the pooling window) and max pooling (determines the maximum value among the neurons). Some studies concluded that max pooling gets a faster convergence during training [8]. Pooling reduces the size of the feature maps and consequently the number of operations of the next convolutional layer. One or more fully connected layers (FC) follows the last convolutional layer with the same structure of the traditional neural network, where all neurons of the layer are connected to all the neurons of the previous layer. The output of the last dense layer associates one neuron to a class of objects. The number of weights, \(NW_{FC}\), associated with a fully connected layer depends on the number of kernels, \(nk\), and the size of the uni-dimensional kernel, \(ks\), equal to the number of neurons of the previous layer, and is given by:  
\[NW_{FC}=nk\times(ks+1)\]  
The number of multiply-accumulations (MACC), \(MACC_{FC}\) is the same as the number of weights, since each weight of a fully connected layer is used only once for each input image. Figure 3: Different pooling functions applied to a feature map. All neurons of convolutional and fully connected layers are followed by a linear or non-linear activation function, depending on the application domain [9]. A well-known activation function is the sigmoid given by \(\frac{1}{1+e^{-z}}\). It is used to predict a probability since it varies between 0 and 1. For a multiclass classification, the softmax function is used.