# Deep Learning Model for the Inspection of Coffee Bean Defects
## 1 Introduction
### Cnn  
The CNN is a LeNet network proposed by LeCun that performs supervised learning with backpropagation. It transforms an original image into a series of feature images through interconnected convolutional and pooling layers. A fully connected layer then classifies the original image according to the image's features. The CNN framework is mainly divided into three components, namely a convolutional neural network, a fully connected neural network, and a classifier. An input image is passed through the convolutional layer, which enhances and extracts the features of the image. The dimensionality of the extracted features is then reduced by the convolutional layer before they enter the fully connected layer for classification. The CNN randomly generates kernels to extract different image features. The generated features are stored in new neurons, and model training determines the importance of each neuron. In general, forward propagation involves the use of random kernels to extract image features, which are then transferred to subsequent neurons. By contrast, backpropagation entails model training to determine the importance of neurons. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Method** & **Strength** & **Weakness** \\ \hline Principal component analysis & \
\begin{tabular}{c} extract vector features from images \\ the number of features is adjustable \\ extract appearance features \\ identify the appearance differences of different varieties \\ extract features associated with the overall image \\ evenness and color concentration \\ extract features associated with color differences \\ identify stains caused by lesions. \\ high learning ability \\ suitable for image recognition in various fields \\ \end{tabular} &
\begin{tabular}{c} small components may be ignored \\ features associated with color and brightness \\ cannot be extracted \\ image background will affect the uniformity of the image \\ less sensitive toward changes in shapes than \\ are other methods \\ large amount of calculation \\ large amount of calculation \\ \end{tabular} \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Comparison of different feature extraction methods. During forward propagation, the kernel \(w_{mn}\) is input into the CNN to perform the convolution of an image. In (1), b is the bias, and the convolutional output matrix \(y_{ij}\) is computed using the activation function f to generate a new neuron \(Z_{ij}\) (2). \[y_{ij}=\sum_{m=1,n=1}^{M,N}\left(x_{i+m-1,j+n-1}*w_{mn}\right)+b \tag{1}\]  
\[Z_{ij}=f\big{(}y_{ij}\big{)} \tag{2}\]  
In a convolution operation, the bias generated from multiplication and addition only entails the use of linear equations and therefore simple computation because the addition of multiple layers of linear equations only yields a single linear regression model. However, the learning efficiency of this approach is limited. Activation functions are used to introduce nonlinear elements, enable more complex propagation among neurons, and enhance the learning performance of a network. The pooling layer usually follows the convolutional layer and reduces the dimensionality of a sample. Common types of pooling layers include the max pooling and average pooling layers, which calculate the mean and maximum value within a masked area, respectively. The goal of the pooling layer is to enhance features while reducing image dimensionality. With the development of CNN, novel architectures such as VGG, GoogLeNet, and resNet were proposed in recent years. VGG [11] is an improvement of AlexNet, which can effectively extract the subtle features in the image by superimposing multiple small-size convolutional layers. This makes VGG widely used for defect detection after AlexNet. In GoogLeNet [12], the inception architecture is used to replace the convolutional layer. The inception architecture can be regarded as multiple convolutional layers in parallel, and different features are extracted through convolutional layers and pooling layers with different filter sizes.