# A Plant Disease Classification Algorithm Based on Attention MobileNet V2
## 2 Materials and Methods
### MobileNet Algorithm Based on Dual Attention  
The main features of MobileNet V2 include: (1) the adoption of depth separable convolution in place of ordinary convolution to reduce model computation and parameter requirements; (2) the introduction of reverse residual structure to increase the number of network layers and enhance feature expressiveness; (3) replacement of nonlinear structures with linear Bottleneck structures to minimize the loss of low-dimensional feature information. Based on the low power consumption characteristics of MobileNet V2 [37], MobileNet V2 has been selected as the main backbone network and improved through adjustments in width factor, attention module and multi-scale feature fusion. The network block diagram is shown in Figure 4.  
Figure 4: Attention-based MobileNet framework. The depth-separable convolution replaces the standard convolution with fewer parameters and computation [38]. The computation ratio of the depth-separable convolution with the standard convolution is given by:  
\[H=\frac{D_{f}^{2}D_{k}^{2}M+D_{f}^{2}MN}{D_{f}^{2}D_{k}^{2}MN}=\frac{1}{N}+\frac {1}{D_{k}^{2}} \tag{24}\]  
where \(D_{f}\) represents the length of the input feature map and the number of channels, \(D_{k}\) is the length of depthwise convolution (\(DW\)) convolution kernel, and \(M\) is the number of pointwise convolution channels. In feature extraction, the usual convolution kernel size is 3 \(\times\) 3. The computation amount and parameter quantity of depth-separable convolution are approximately 1/9 of conventional convolution. MobileNet V2 incorporates the concept of ResNet and proposes the reverse residual structure. There are two typical methods: In the first method, PW convolution is used to increase the dimension, and \(DW\) convolution is used to extract the features from each channel, and PW convolution is then employed to reduce the feature dimensionality. When the step size is 1, a residual connection is established, while a series connection is established when the step size is 2; S The second method of the reverse residual structure first increases and then reduces dimensionality, which allows the network to accommodate smaller input and output dimensions, so as to reduce the computational load and parameters. At the same time, the residual connection can improve gradient propagation efficiency, with a deeper network layer. An important parameter in the network is the width factor, which adjusts the number of convolution kernels in each module of the network to \(\alpha\) times the original one, and the corresponding calculation load is:  
\[T=\alpha D_{f}^{2}D_{k}^{2}M+\alpha^{2}D_{f}^{2}MN \tag{25}\]  
By adjusting \(\alpha\), the computational burden of the model is greatly reduced. CBAM is an attention mechanism module that integrates channel and space [39]. It is embedded in a convolutional neural network for end-to-end training. The final channel attention is illustrated in Figure 5a. \[M_{c}(F)=\sigma\big{(}W_{1}W_{0}F_{avg}+W_{1}W_{0}F_{max}\big{)} \tag{26}\]  
where \(F\) is the input feature map, \(\sigma\) is the nonlinear activation function, \(W_{i}\) is the weight of layer \(i\), and \(F_{avg}\) and \(F_{max}\) are the results of input \(F\) after the average pooling and kernel maximum pooling, respectively. The spatial attention mechanism is shown in Figure 5b: the channel direction is averaged, and the kernel is maximally pooled to generate a feature description of size \(2\times H\times W\), and the feature vector is obtained and activated by a convolution operation. The corresponding spatial attention mapping model is as follows:  
\[M_{s}(F)=\sigma\big{(}f\big{(}f_{c}(F_{avg}+F_{\max})\big{)}\big{)} \tag{27}\]  
where \(f\) is the convolution operation, and \(f_{c}\) is the join operation. The complete calculation process of the CBAM module is  
\[ \begin{array}{l}FA=M_{s}(F^{\prime})F^{\prime}\\ F^{\prime}=M_{c}(F)F\end{array}