# A Mobile-Based System for Detecting Ginger Leaf Disorders Using Deep Learning
## 3 Materials and Methods
### Detection Approach  
The deep learning models are also very useful in detecting and localizing the affected part of the input image. In this regard, various state-of-the-art models are available in the literature. For instance, in this work, we tested one of the commonly used detection models, YOLOv5, for the pest pattern, nutrient deficiency, and healthy leaf detection. Furthermore, the model is also being tested for detecting soft rot disease and healthy leaves using the seed images collected in the field.  
\begin{table}
\begin{tabular}{l l} \hline \hline Dataset & Healthy and effected class for each pest pattern, nutrient deficiency, and soft rot disease with the ratio of 70\% and 30\% for training and testing, respectively \\ \hline Pre-processing & Data renaming and resizing to 150 \(\times\) 150 \\ \hline Batch size & 16, 32, 64, and 128 \\ \hline Epochs & 42, 50, 64, and 70 \\ \hline Learning rate & 0.001 \\ \hline Optimization & Adam optimizer \\ \hline \hline \end{tabular}
\end{table}
Table 1: Training hyper parameters for CNN, MobileNetV2 and VGG-16.  
The working of the deployed model YOLOv5n is generally explained in the network architecture (see Figure 5). The model mainly consists of three components, e.g., the backbone, neck, and head. CSPDarknet [35] is used for feature extraction at the backbone. This is responsible for solving the issue related to the repetition of gradient information during the network training by fusing gradient changes with the feature map from start to finish. This resulted in reducing model the parameters while increasing the detection performance. In this part, two CSP structures (one residual and one non-residual) are used. In addition, spatial pyramid pooling (SPP) [36] is also used to solve anchor and feature map alignment issues. The next part of the neck layer is the combination of FPN and PANet [37]. This layer is responsible for feature fusion and performs multi-scale prediction across various layers. This helps in the enhancement of semantic representation and localization at different scales. Moreover, the CBL layers are further concatenated in the last step in order to extract the pixel information for mask formation. In the prediction part, the model uses a joint loss function using bounding box regression, classification, and confidence and is expressed as follows:  
\[L=L_{clc}+L_{bx}+L_{conf} \tag{1}\]  
where \(L_{clc}\) is used to represent the classification error, \(L_{bx}\) represents the bounding box regression error, and \(L_{conf}\) shows the confidence error.  
The \(L_{clc}\) is computed as follows:  
\[L_{clc}=\sum_{i=0}^{k^{2}}l_{i}\sum_{c=1}^{C}E(\hat{p}_{i}(c),p_{i}(c)) \tag{2}\]  
where \(l_{i}\) takes either 1 or 0 for class objects and \(\hat{p}\) and \(pi\) show predicted and true probability. The \(L_{bx}\) is computed as follows:  
\[L_{bx}=1-IoU(A^{p},A^{g})+\frac{A^{c}-A^{p}-A^{g}+I}{A^{c}} \tag{3}\]  
where it is also known as a generalized intersection over union (GIoU) localization loss. It is useful to locate a closed bounding box bounded by the predicted box \(A^{p}\) and the true  
Figure 5: The architectural diagram of the YOLOv5 model.  
box \(A^{S}\). Here, \(A_{c}\), \(C\), and \(I\) are used for the desired area, the overlapping area, and the real area, respectively. The intersection ratio of the estimated and real area in the image frame is represented by \(IoU\). \(L_{conf}\) is calculated as follows:  
\[L_{conf}=\sum_{i=0}^{k^{2}}\sum_{j=0}^{M}I_{i,j}E(\hat{C}_{i},C_{i})-\lambda_{no }\text{obj}\sum_{i=0}^{k^{2}}\sum_{j=0}^{M}I_{i,j}(1.I_{i,j})E(\hat{C}_{i},C_{i}) \tag{4}\]  
\(k^{2}\) depicts image partitioning into \(k\times k\) grids, yielding m candidate anchors. \(I_{i,j}=0 or1\) denotes negative or positive samples. The confidence levels of the \(i\)th predicted bounding box and the true bounding box are represented by \(C_{i}\) and \(C_{i}\), respectively. Moreover, \(E(.)\) indicates a binary cross-entropy loss and is defined by:  
\[E(\hat{X}_{i},X_{i})=\hat{X}_{i}ln(X_{i})+(1-\hat{X}_{i})ln(1-X_{i}) \tag{5}\]