# A Plant Disease Classification Algorithm Based on Attention MobileNet V2
## 2 Materials and Methods
### Multilevel Feature Extraction Algorithm  
The OTSU algorithm [34] achieves image segmentation through the calculation of the image gray features to determine the threshold. The principle is to maximize the inter-class  
Figure 1: Experiment database. Figure 2: Algorithm flow chart. variance between the objects and the background of the image. It serves as an automatic optimization algorithm for image segmentation. The total number of pixels in the image is notated as \(N\), and the pixel gray level as \(G\). \(f_{i}\) represents the number of pixels at gray level \(i\). The threshold \(t\) is selected to divide the analysis into two categories: \(C_{0}\) and \(C_{1}\). Then, the corresponding probability of the two categories can be expressed as:  
\[ \begin{split} w_{0}&=P(C_{0})=\sum\limits_{i=1}^{t }P_{i}=w(t)\ \ \ \ \ P_{i}=f_{i}/N\\ w_{1}&=1-w(t)\end{split}  \tag{1}\]  
The inter-class variance of each pixel \(\sigma_{B}^{2}(t)\) is selected as the evaluation index:  
\[\sigma_{B}^{2}(t)=\frac{\left[\mu_{r}w(t)-\mu(t)\right]^{2}}{w(t)[1-w(t)]} \tag{2}\]  
\[\mu_{r}=\mu(L)=\sum\limits_{i=1}^{L}iP_{i},\ \ \ \ \ w(t)=\sum\limits_{i=1}^{t}P_{i} \tag{3}\]  
Then, the optimal threshold \(T\) is determined. \[\sigma_{B}^{2}(T)=\max\limits_{1\leq t\leq l}\left\{\sigma_{B}^{2}(t)\right\} \tag{4}\]  
The traditional OTSU algorithm considers the neighborhood information. However, in cases where there is minimal distribution difference between background features and target pixels, the two peaks may not be clearly defined, resulting in a poor segmentation effect. To improve the traditional OTSU image processing method, the weighted Naive Bayes algorithm is introduced to refine the segmentation effect. The naive Bayes algorithm is a commonly utilized data classification algorithm in machine learning algorithm research [35]. Thanks to its strong theoretical support, it boasts high classification efficiency and has been continuously studied and applied across different fields. Firstly, the Bayes principle is introduced:  
\[P(c\,|\,X)=\frac{P(X|c)P(C)}{P(X)} \tag{5}\]  
where \(P(c\,|\,X)\) represents the posterior probability that \(X\) belongs to the category \(c\). \(P(c)\) and \(P(X)\) denote the prior probabilities of category \(c\), and conditional \(X\). \(P(X\,|\,c)\) represents the posterior probability that category \(c\) belongs to the condition \(X\). Suppose the dataset comprises \(m\) attribute variables denoted as \(A\), and the category variables are \(C=\{c_{1},\,c_{2},\,\ldots c_{n}\}\). The Naive Bayes model is obtained  
\[c(x)_{NB}=\underset{i}{\text{arg max }}P(c_{k})\prod\limits_{i=1}^{m}P(x_{i}|c _{k}),\ \ \ \ \ 1\leq k\leq n \tag{6}\]  
where \(P(c_{k})\) is the prior probability when category \(c\) takes the value of \(k\); \(P\left(x_{i}\,|\,c_{i}\right)\) represents the posterior probability that category \(c_{i}\) belongs to the condition \(x_{i}\). The traditional naive Bayes model presupposes that different attributes are independent of one another, which is difficult to achieve in practice. In cases where there is a correlation between certain attributes, it greatly reduces the classification efficiency of the model, resulting in inaccurate experimental results. Therefore, attribute weighting is employed to retain the high classification accuracy of the traditional naive Bayes algorithm. The approach also alleviates the negative impact caused by the special condition of attribute independence, which improves and enhances the efficiency of the traditional algorithm to a large extent. The corresponding formula is  
\[c(x)_{P}=\text{arg max }_{i}P(c_{k}){\prod\limits_{i=1}^{m}P(x_{i}|c_{k})^{w(i)}}, \quad\quad 1\leq k\leq n \tag{7}\]  
where \(w_{i}\) represents the weight value of the class attribute \(A_{i}\), exerting control over the segmentation effect. The key to the improved classification algorithm lies in the precise determination of the corresponding weight value of each attribute to yield superior results.