# Imperfect Wheat Grain Recognition Combined with an Attention Mechanism and Residual Network
## 3 Results and Discussion
### Comparison of Identification Results  
The dataset used for the test included perfect wheat grains and five types of imperfect wheat grains, each of which consisted of 100 images (100 \(\times\) 100 pixels), which resulted in a total of 600 images. Precision, recall and F-measure were used as indicators to evaluate the performance of the model, and the calculation method was as follows:  
\[\text{Precision}=\frac{\text{TP}}{\text{TP}+\text{FP}}\times 100\% \tag{7}\]  
\[\text{Recall}=\frac{\text{TP}}{\text{TP}+\text{FN}}\times 100\% \tag{8}\]  
\[\text{F}-\text{measure}=2\times\frac{\text{Precision}\times\text{Recall}}{ \text{Precision}+\text{Recall}} \tag{9}\]  
In the formula, TP represents the number of positive samples labeled as positive samples; that is, the correct number of imperfect wheat grains identified as that kind of wheat. FP represents the number of negative samples incorrectly labeled as positive samples; that is, the imperfect wheat grains species classified as one kind of wheat where they were actually another kind of imperfect wheat. FN represents the number of positive samples that were incorrectly labeled as negative samples; that is, imperfect wheat grain species of this type of wheat were incorrectly classified as another kind of imperfect wheat. According to the above experimental comparison, the optimal network model without an attention mechanism and with an adding attention mechanism is the ResNet-50 model. Therefore, a confusion matrix was drawn and the precision recall rate and weighted F-measure were calculated to further compare the recognition accuracy of various types of perfect and imperfect wheat grains using ResNet-50. Tables 3 and 4, respectively, present the ResNet-50 confusion matrix and performance analysis, with and without an attention mechanism. According to the F-measure values in Table 3, the classification results of \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Method** & **Batch** & **Parameters** & **Epoch** & **Time** & **Accuracy (\%)** \\ \hline ResNet-18 & 32 & 11,189,190 & 100 & 1 h 27 m 25 s & 94.17 \\ ResNet-34 & 32 & 21,304,774 & 100 & 2 h 27 m 54 s & 94.83 \\ ResNet-50 & 32 & 23,573,446 & 100 & 3 h 27 m 54 s & 95.33 \\ ResNet-101 & 32 & 42,617,798 & 100 & 5 h 34 m 21 s & 95.17 \\ ResNet-152 & 32 & 58,307,526 & 100 & 7 h 45 m 19 s & 95.17 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Parameters and results of the training model. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Method** & **Batch** & **Parameters** & **Epoch** & **Time** & **Accuracy (\%)** \\ \hline ResNet-18 & 32 & 11,279,054 & 100 & 2 h 13 m 9 s & 95.17 \\ ResNet-34 & 32 & 21,467,538 & 100 & 3 h 59 m 52 s & 95.50 \\ ResNet-50 & 32 & 26,106,006 & 100 & 5 h 24 m 52 s & 96.50 \\ ResNet-101 & 32 & 47,398,744 & 100 & 9 h 42 m 9 s & 96.17 \\ ResNet-152 & 15 & 64,941,466 & 100 & 24 h 26 m 34 s & 94.83 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Parameters and results of the training model with attention mechanism. various types of imperfect wheat grains in the ResNet-50 model were similar, reaching more than 94%. By comparing the values in Tables 3 and 4, it can be seen that the ResNet-50 network model with an attention mechanism is superior to the ResNet-50 model without an attention mechanism in terms of the recognition rate of all kinds of imperfect wheat grains. After comparing Tables 3 and 4, we found that the F-measure value of the ResNet-50 network with an attention mechanism only increased the mildew category by 0.09% compared with the traditional ResNet-50 network. According to the confusion matrix, we can see that the model with an attention mechanism mistakenly classified six mildew wheat grains as sprouted wheat grains; as a result, the precision value of the sprouted category and recall value of the mildew category decreased, and the F-measure value of these two categories was significantly lower than that of other categories. We tested the inference time of the traditional ResNet-50 and the ResNet-50 with an attention mechanism.