# Wheat Ear Detection Algorithm Based on Improved YOLOv4
###### Abstract  
The continuously growing population requires improving the efficiency of agricultural production. Wheat is one of the most wildly cultivated crops. Intelligent wheat ear monitoring is essential for crop management and crop yield prediction. Although a variety of methods are utilized to detect or count wheat ears, there are still some challenges both from the data acquisition process and the wheat itself. In this study, a computer vision methodology based on YOLOv4 to detect wheat ears is proposed. A large receptive field allows viewing objects globally and increases the connections between the image points and the final activation. Specifically, in order to enhance the receptive field, additional Spatial Pyramid Pooling (SPP) blocks are added to YOLOv4 at the feature fusion section to extract multi-scale features. Pictures of wheat ears taken at different growth stages from two different datasets are used to train the model. The performance of the proposed methodology was evaluated using various metrics. The Average Precision (AP) was 95.16% and 97.96% for the two datasets, respectively. By fitting the detected wheat ear numbers and true wheat ear numbers, the R2 value was 0.973. The results show that the proposed method outperforms YOLOv4 in wheat ear detection. It indicates that the proposed method provides a technical reference for agricultural intelligence. object detection; wheat ear; convolutional neural network; intelligent agriculture
handcrafted features. Manually designing features limits the utilization of conventional computer visions. Deep learning is becoming a dominant tool in computer vision, including Transformers and Convolutional Neural Networks (CNN) [7; 8]. Transformer, i.e., a mechanism of self-attention, is becoming an alternative of CNN for object detection. It achieves state-of-the-art results with a very large training dataset [9; 10; 11; 12]. However, in the case of a limited dataset, object detection architectures with CNN perform better. CNN replaces handcrafted feature engineering by automatically learning features from big data. Algorithms based on CNN fall into two categories, i.e., semantic segmentation and object detection. Semantic segmentation marks the presence of an object through pixel-wise masks generated for each object in the image. It labels each pixel in the image with a category label to mark the presence of a wheat ear. The patches containing the wheat ears are positive samples, and the remaining regions in the image are treated as negative samples. Semantic segmentation deep learning neural networks are trained with the annotated dataset. Finally, the trained neural network can segment all the wheat ears pixel-wisely in the input image. [PERSON] et al. used CNN architecture to segment wheat ears in images [13]. [PERSON] et al. used a two-stage segmentation method to detect wheat ears in the image, with the coarse segmentation stage classifying super-pixels and the fine segmentation stage eliminating the non-ear pixels [14]. Semantic segmentation has achieved great success in assigning a category label to each pixel in the image, so it is beneficial in detecting diseased areas on the spikes [15]. However, fine segmentation is based on pixel-level annotation, which is trivial and time-consuming. Post-processing is needed because the mask output is not directly related to the number of wheat ears [16]. Moreover, due to the lack of global shape models, semantic segmentation does not perform well in detecting hypotheses of objects in cluttered backgrounds [17]. Object detection is often formulated as predicting object classes and bounding boxes enclosing the objects of interest in the image, which can be divided into two categories, one-stage detector and two-stage detector. Two-stage detector first utilizes a region proposal network to generate regions with a high probability of containing objects in the first stage and then feeds the region proposals down the pipeline for classification and bounding boxes regression in the second stage. [PERSON] et al.