# Wheat Ear Detection Algorithm Based on Improved YOLOv4
## 3 Results and Discussion
### Model Training  
In the training phase, the models were trained for 100 epochs with batch size 4; 10% of the data was used as the validation set. Stochastic gradient descent (SGD) was used to optimize the model. The weight decay was \(5\times 10^{-4}\). We set the initial learning rate as 0.001. The curves of loss function values during the training process are shown in Figure 2. The loss value drops dramatically in the initial 20 epochs. After that, the training loss continues to decrease in almost every epoch. The validation loss curve follows the training loss curve closely, which means no overfitting in the training process. Here, 20% of the dataset was set as a test dataset. In order to verify the performance of the proposed model for wheat ear detection, comparative experiments were conducted using the improved YOLOv4, the original YOLOv4 [28] did a good job at wheat ear detection using, i.e., CBAM-YOLOv4. They also used the HRED [19] and GWHD dataset, so results were compared with [28]. The performance evaluation results with these datasets are listed in Tables 1 and 2. AP is one of the most important metrics for object detection. AP provides a model-wide evaluation considering the trade-off between Precision and Recall. Precision-Recall curves of the two datasets are shown in Figure 3. For the HRED dataset, as can be seen from Figure 3a and Table 1, the AP of the proposed algorithm was 95.16%, which is a remarkable improvement compared with YOLOv4. \(F_{1}\) remained the same as YOLOv4. With the 0.5 score threshold, Precision and Recall were 96.91% and 79.00% for the proposed algorithm, respectively. Precision had a 1.82% improvement compared with YOLOv4. The recall value was slightly smaller than YOLOv4, but the two values were very close. FPS is used to measure detection speed. The FPS of the proposed algorithm was 51.78, which is at the same level as YOLOv4. It is believed the reason for the FPS decline is that the added SPP modules consumed extra computing time. When comparing the results of the proposed algorithm with CBAM-YOLOv4, it can be seen that the AP of the proposed algorithm was 1.24% smaller, and \(F_{1}\) was 0.06 smaller. This demonstrates the benefits of using the attention method. There was no FPS value in CBAM-YOLOv4 provided for this dataset. The detection metrics were also calculated based on the GWHD dataset. Table 2 lists all the evaluation results based on the GWHD dataset. The Precision-Recall curve is shown in Figure 3b. In this case, the proposed algorithm had the highest AP, \(F_{1}\), and Precision values compared with YOLOv4 and CBAM-YOLOv4, and its superiority is very salient. The FPS of the proposed algorithm had a 0.36 improvement compared with YOLOv4. There is no FPS value in CBAM-YOLOv4 provided. Despite the Recall value of the proposed algorithm being a little smaller than CBAM-YOLOv4, considering the overall performance, it can be concluded that the proposed algorithm works significantly better in the GWHD dataset. Considering the overall performance, it can be concluded that the proposed algorithm is effective for detecting wheat ears. Figure 2: Loss function value curves of Improved YOLOv4. Based on the above analysis, it can be concluded that the proposed algorithm achieves state-of-the-art object performance and performs even better in most of the critical evaluation metrics. It demonstrates the effectiveness of the proposed method. Some detection results are shown as examples in Figure 4. The top two images are from the HRED dataset, and the bottom two are from the GWHD dataset. It can be seen from the figures that most of the wheat ears are detected effectively. The real numbers, i.e., manually counted numbers and detected numbers of wheat ears in the four images, are listed in Table 3. The detected wheat ears are marked using red and yellow boxes. In Figure 4a, 170 objects were detected, 5 failed, and the accuracy was 97.14%. In Figure 4b, 132 objects were detected, 2 failed, and the accuracy was 98.5%.