# A Lightweight YOLOv8 Model for Apple Leaf Disease Detection
## 2 Materials and Methods
### Design for the YOLOv8-GGi Model
#### 2.3.3 BiFPN Feature Fusion Network  
In training models to recognize apple leaf diseases, leaf surface lesions' varying shapes and sizes result in feature representations of differing resolutions [42]. Combining these features using a traditional linear superposition approach within PANet can cause disproportionate emphasis on features from more prominent leaf spots in the aggregated output. Such an imbalance often results in the prominence of more extensive lesions, overshadowing the finer details of smaller lesions, and may lead to missed detections of these less conspicuous targets. To mitigate this risk, it is essential to safeguard against the loss of high-resolution, shallow features, as they hold the key details necessary for identifying small-scale anomalies on the leaf surface. Figure 9 shows the structures of FPN and PANet in YOLOv8.  
To address the morphological diversity observed among various diseases at different stages of development, as well as the size and shape variations within diseases of the same category, we introduce the BiFPN structure instead of the original PAFPN structure [43] in the original multiscale feature fusion network of YOLOv8 and improve the BiFPN structure based on this to increase the size of the P2 large-size feature layer to increase the feature fusion capability of the apple tiny lesion vision target. The improved BiFPN structure is shown in Figure 10.  
During the feature fusion process, the input features have different resolutions, so their influence on the output features varies. Apple leaf spots usually have a variety of irregular shapes. BiFPN balances the weights of different features by using a fast normalized fusion module, which helps to dig deeper into the information of small target spots on apple leaves, thus reducing the phenomena of misdetection and omission caused by the complexity of the environment. Equation (9) gives the connection between the inputs and the outputs.  
\[O=\sum_{i}\frac{\omega_{i}}{\epsilon+\sum_{j}\omega_{i}}I_{i}, \tag{9}\]  
where \(\omega_{i}\) denotes the corresponding learning weights of the input feature \(\mathrm{I}\). These weights are adjusted using the ReLU activation function to ensure that the value of \(\omega_{i}\) is non-negative. The initial learning rate is set to 0.0001 to prevent unstable values, and the normalized weights are controlled to decrease in the range of 0 to 1.  
Figure 9: FPN and PANet structure in YOLOv8; P3–P7 are the input feature maps of different layers: (**a**) FPN and (**b**) PANet.  
\[P_{4}^{th}=Conv\left(\frac{\omega_{1}\cdot P_{4}^{in}+\omega_{2}\cdot Resize\big{(}P_ {5}^{in}\big{)}}{\omega_{1}+\omega_{2}+\varepsilon}\right), \tag{10}\]  
\[P_{4}^{out}=Conv\Bigg{(}\frac{\omega_{1}^{\prime}\cdot P_{4}^{in}+\omega_{2}^{ \prime}\cdot P_{4}^{ld}+\omega_{3}^{\prime}\cdot Resize\big{(}P_{3}^{out} \big{)}}{\omega_{1}^{\prime}+\omega_{2}^{\prime}+\omega_{3}^{\prime}+\varepsilon} \Bigg{)}, \tag{11}\]  
Using the feature layer P\({}_{4}\) as an example, Resize represents it as maybe the up-sampling or down-sampling operation. This method ensures that the different input features are weighted according to their significance during the fusion process to effectively extract deep information about small target lesions on apple leaves and minimize misdetections or omissions caused by environmental factors.