# Kiwifruit Detection Method in Orchard via an Improved Light-Weight YOLOv4
## 3 Kiwifruit Recognition Network
### YOLOv4 Object Detection Model Improvement
#### 3.2.2 Improved YOLOv4 Network Model  
The structure of the improved YoloV4 network model is shown in Figure 7. The feature layers with the same width and height as in CSP-Darknert53 are found from GhostNet, and these feature layers are passed into the enhanced feature network to realize the application of GhostNet in YOLOv4 network. Kiwifruit as recognition targets vary in scale, and most of them are small target fruits. The small target feature information is rough in location information and feature information is easily lost when processed by feature fusion, which causes false detection and missed detection in the network model. To improve the detection accuracy of the original model for small kiwifruit targets, 104 \(\times\) 104 feature layers are added to aggregate the shallow feature information. Four scale feature layers of 13 \(\times\) 13, 26 \(\times\) 26, 52 \(\times\) 52, and 104 \(\times\) 104 (q4) are output from the backbone network. q4 sensory field is suitable for small object detection, and the q4 feature layer is fused with the previous feature layer by downsampling to enhance the extraction of small target feature information. Drawing on the Ghost Module network, this study proposes to use a combination of 1 \(\times\) 1 convolution and depth-separable convolution to replace part of the normal convolution in the YOLOv4 feature extraction network, and use it as the main module to adjust the number of channels and perform inter-channel feature fusion, which can reduce the computational pressure brought by the fused feature layer q4. The Alpha parameter is introduced into the network model to replace the number of channels inside PAnet by using the parameter to adjust the parameter to improve part of the channel number adjustment in order to reduce the parameter redundancy. Figure 6: The model structure of the improved YOLOv4 network. The loss function for network training includes regression loss function Loss(cord), confidence loss function Loss(conf) and classification loss function Loss(cls). The loss function formula is as Equations:  
\[\text{Loss }=\text{ Loss(coord)}+\text{Loss(conf)}+\text{Loss(cls)} \tag{2}\]  
\[\text{Loss(coord)}=\lambda_{\text{coord}}\sum_{\text{i=0}}^{\text{K}\times \text{K}}\sum_{\text{j=0}}^{\text{M}}\text{I}_{\text{ij}}^{\text{obj}}(2-1 \times\text{h}_{\text{i}})[\text{L}_{\text{CIOU}}] \tag{3}\]  
\[\text{Loss(conf)}=-\sum_{\text{i=0}}^{\text{K}\times\text{K}}\sum_{\text{j=0}}^ {\text{M}}\text{I}_{\text{ij}}^{\text{obj}}[\hat{\text{C}}_{\text{i}}\text{lgC }_{\text{i}}+(1-\hat{\text{C}}_{\text{i}})\text{lg}(1-\text{C}_{\text{i}})]- \lambda_{\text{noobj}}\sum_{\text{i=0}}^{\text{K}\times\text{K}}\times\sum_{ \text{j=0}}^{\text{M}}\text{I}_{\text{ij}}^{\text{noobj}}[\hat{\text{C}}_{ \text{i}}\text{lgC}_{\text{i}}+(1-\hat{\text{C}}_{\text{i}})\text{lg}(1-\text {C}_{\text{i}})] \tag{4}\]  
\[\text{Loss(cls)}=-\sum_{\text{i=0}}^{\text{K}\times\text{K}}\text{I}_{\text{ ij}}^{\text{obj}}\sum_{\text{ecclasses}}[\hat{\text{p}}_{\text{i}}(\text{c}) \text{lgp}_{\text{i}}(\text{c})+(1-\hat{\text{p}}_{\text{i}}(\text{c}))\text{ lgf}(\text{c}))] \tag{5}\]  
where, K represents the grid size, I denotes the i-th square of the feature map, j denotes the j-th predicted frame of the square, w and h represent the width and height of the ground truth, respectively, obj and noobj denote the presence and absence of objects in the i-th square, respectively, C\({}_{\text{i}}\) and \(\hat{\text{C}}_{\text{i}}\) denote the categories of predicted and true frames, respectively p\({}_{\text{i}}(\text{c})\) is the confidence level of the predicted target, \(\hat{\text{p}}_{\text{i}}(\text{c})\) is the confidence level of the actual target, \(\lambda_{\text{coord}}\) and \(\lambda_{\text{noobj}}\) are the penalty coefficients, and L\({}_{\text{CIOU}}\) is the regression loss function of the bounding box. Figure 7: The framework of the improved YoloV4 network model.