# Wheat Ear Detection Algorithm Based on Improved YOLOv4
## 2 Materials and Methods
### Improved YOLOv4 to Enhance Receptive Field  
A large receptive field allows viewing the entire object, viewing the context around the object, and increasing the number of connections between the image point and the final activation [24]. Spatial Pyramid Pooling (SPP) is an effective tool to enhance the receptive field and extract multi-scale features. SPP has long been a critical technique in computer vision before the prevalence of CNNs. Considering SPP has remarkable properties, [PERSON] et al. used it in the context of CNNs by replacing the pooling layer after the CNN layer with an SPP layer to eliminate the requirement of fixed-size input image [39]. It partitions the image into divisions from finer levers to coarser levers, and combines local features within them. More concretely, it splits the feature maps from the backbone into several d\(\times\)d blocks, where d can be 1, 2, 3,..... In each spatial bin for the SPP-net, they pool the responses of each filter to obtain a fixed-length representation. The representation would be fed into the fully-connected layers for final object detection. To increase the receptive field and separate context features, a modified SPP block was added over the CSPDarknet53 in YOLOv4 [24]. YOLOv4 inherits the prediction head mechanism of YOLOv3 to predict objects at 3 different scales. In the YOLOv4 framework, 3 convolutional layers are added after the CSPDarknet53 backbone. After that, the SPP module follows with kernel size k\(\times\)k, where k = 1, 5, 9, 13, with stride 1. The outputs of max-poling in the SPP module are concatenated. Then, PANet structure is used to aggregate the parameters, and the results are fed into YOLO head to predict objects. YOLOv4 adds the SPP module to the lowest-resolution feature map, which has the largest receptive field. Nevertheless, wheat ear sizes are usually small in images and their size varies. In order to detect small-size objects and extract multiscale features with more different size receptive fields, two more SPP modules are added to YOLOv4's neck part. The improved YOLOv4 network architecture is shown in Figure 1. The backbone adopts CSPDarknet53. The input image first runs through a convolutional layer with the Mish activation function. Then, the output feature maps run through 5 blocks from Resnet, which deepen the network.  
Three feature maps (FPs) of different scales are extracted from the backbone, which are denoted as FM1, FM2, and FM3, with sizes of 13 \(\times\) 13, 26 \(\times\) 26, and 52 \(\times\) 52. All three feature maps run through 3 convolutional operations before being fed into the SPP blocks. All three SPP blocks have the same kernel size k \(\times\) k, where k = 1, 5, 9, 13 and the strides of all the SPP blocks equal 1. The max-pooling outputs of each SPP block are concatenated individually to increase the dimension of tensors. More meaningful semantic information is obtained from the up-sampled feature maps and finer-grained information is obtained from earlier feature maps [23] by this method. Three convolutional layers follow to process the concatenated feature maps. Then, the results are fed into the PANet path-aggregation neck, which aggregates parameters from different backbone levels for different detector levels. This improved neck could maintain spatial information and collect feature maps from different stages.