# Deep Learning Model for the Inspection of Coffee Bean Defects
## 3 Results
### Experimental Results  
The training and testing datasets accounted for 80% and 20% of all the samples, respectively. Each batch of 50 samples was used for computation to execute 50 epochs. Figure 8 and Table 5 present the training accuracy, testing accuracy, and kappa of the three constructed models. The experimental results revealed that the modified models had higher accuracy and considerably higher kappa than did the AlexNet-aj model. This finding verified that the modifications conducted in this study, namely enhancing the dimensionality reduction, removing the padding, and introducing the leaky ReLU, considerably improved the feature extraction and generalization of the AlexNet model for detecting coffee bean defects. Figure 8: Accuracy curves of the constructed models. \begin{table}
\begin{tabular}{c c c c c} \hline  & **Alexnet-aj** & **New Network-dr** & **New Network-dr-pv** & **New Network-Final** \\ \hline Acc-train & 95.7\% & 98.0\% & 98.6\% & 98.6\% \\ Acc-test & 90.2\% & 94.4\% & 94.8\% & 95.1\% \\ kappa & 0.891 & 0.928 & 0.937 & 0.935 \\ \hline \end{tabular}
\end{table} 
Table 5: Accuracy of the constructed models. Table 6 presents the performance of the three constructed models. The experimental results show that the params of the New-network-dr model are three times that of Alexnet-aj, and the FLOPs increase by about 80%. The training time only increased by about 40%, and the model test accuracy increased by 4.2%. This shows that the proposed dimensionality reduction convolutional network greatly increases FLOPs and greatly improves the training accuracy. New-network-final has one less convolutional layer than Alexnet-aj. The FLOPs and training time of the two models are not much different, and the test accuracy was greatly improved from 90.2% to 95.1%. It shows that the model proposed in this study has a higher feature extraction ability under a similar amount of calculation. Confusion matrices were used to analyze the efficiencies of the models in predicting each coffee bean type and to determine the error distribution. Convolution visualization was performed to observe the extracted features. Table 7 and Figure 9 present the confusion matrix and convolution visualization results of the AlexNet-aj model, respectively. More false results were observed for the cut and withered samples than for the other samples (Table 7). The extracted features became blurry after entering the third convolutional layer, and the surface texture of the coffee beans became nearly impossible to identify in this layer (Figure 9). The dimensionality reduction computations between Convolutional Layers 1 and 2 and between Convolutional Layers 2 and 3 severely blurred the input image, which caused the images in the subsequent layers to have lost most features (Figure 9). Consequently, the model accuracy could not be improved. Therefore, the new network-dr model was used to perform experiments. Table 8 and Figure 10 present the confusion matrix and convolution visualization results of this model, respectively. \begin{table}
\begin{tabular}{c c c c} \hline \hline  & **Alexnet-aj** & **New** & **New** & **New** \\  & **Network-dr** & **Network-dr-pv** & **Network-Final** \\ \hline Params & 1.91 M 1 & 6.95 M 1 & 4.26 M 1 & 4.26 M 1 \\ FLOPs & 100.41 M 1 mac & 185.13 M 1 mac & 123.53 M 1 mac & 123.53 M 1 mac \\ Training time & 359 s & 519 s & 414 s & 433 s \\ \hline \hline \end{tabular} 1  
\end{table} 
Table 6: Performance of the constructed models.