# Sugarcane Stem Node Recognition in Field by Deep Learning Combining Data Expansion
## 3 Methodology
### YOLO v4 Algorithm Training Process  
In order to realise the rapid detection of sugarcane stem nodes based on YOLO v4, the model weights of YOLO v4 were pre-trained on the Microsoft Common Objects (Context MS CoCo) dataset, and the model parameters of the network input size, number of categories, batch size and learning rate were fine-tuned. The total number of training epochs was 84, and the first 25 epochs were freezing training, which can ensure that the initial weight was not destroyed and speeds up the training. The main settings are shown in Table 3.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter** & **Value** \\ \hline Input size & 416 \(\times\) 416 \\ Learning rate (freeze epoch) & \(1\times 10^{-3}\) \\ Learning rate & \(1\times 10^{-4}\) \\ Batch size (freeze epoch) & 8 \\ Batch size & 2 \\ Classes & 1 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Parameter settings.  
The training set and testing set were used to train and test the YOLO v4 sugarcane stem node detection model. As shown in Formulas (1)-(4), the loss function used to train the YOLO v4 sugarcane stem node detection model mainly included the position loss of the bounding box, the confidence loss and the classification loss.  
\[Loss=L_{CIoU}+L_{confidence}+L_{class} \tag{1}\]  
\[L_{CIoU}=1-IOU+\frac{d^{2}}{c^{2}}+\alpha\
u \tag{2}\]  
The \(c\) and \(d\) in Formula (2) are the distance between the centres of the two bounding boxes and the diagonal distance of their union, respectively.  
\[L_{confidence}=\sum_{i=0}^{S^{2}}\sum_{j=0}^{B}K[-\log(p)+BCE(\hat{n},n)] \tag{3}\]  
\[L_{class}=\sum_{i=0}^{S^{2}}\sum_{j=0}^{B}1_{ij}^{nobj}[-\log(1-p_{c})] \tag{4}\]  
Figure 4: Detection of sugarcane stem nodes in a complex natural environment based on YOLO v4.  
\(S\) is the number of grids and \(B\) is the anchor number corresponding to each grid in Formulas (3) and (4).  
\[IOU\big{(}A,A^{\prime}\big{)}=\frac{A\cap A^{\prime}}{A\cup A^{\prime}} \tag{5}\]  
where _IOU_, as an abbreviation for Intersection over Union, is the ratio of the intersection and union of the ground truth (\(A\)) and the predicted value boundary boxes (\(A^{\prime}\)) in Formula (5).  
\[BCE(\hat{n},\ n)=-n\log(n)\ -\ (1-\hat{n})\log(1-n) \tag{6}\]  
where _BCE_ represents the cross-entropy loss function of the true value (\(n\)) and the predicted value (\(\hat{n}\)).  
\[\
u=\frac{4}{\pi^{2}}\bigg{(}\arctan\frac{w^{gt}}{h^{gt}}-\arctan\frac{w}{h} \bigg{)}^{2} \tag{7}\]  
where \(w^{gt}\) and \(h^{gt}\) are the height and width of the ground truth bounding box, and w and h represent the width and height of the predicted bounding box.  
Formula 8 was derived jointly from Formulas (5) and (7).  
\[\alpha=\frac{\
u}{(1-IOU)+\
u} \tag{8}\]  
\[K=1_{i,j}^{obj} \tag{9}\]  
In Formula (9), \(K\) stands for weight. If there is an object in \(K\), its value is 1. \(p\) is the probability that the detection object is a sugarcane stem node.  
Figure 5 shows the total loss function curve during training. In the initial training stage of the sugarcane stem node detection model, the model learning efficiency was high, and the training converged fast. With the deepening of the training, the slope of the training curve decreased gradually. When the number of training iterations reached 80, the model learning gradually stabilised.  
The detection result of sugarcane stem nodes based on YOLO v4 is shown in Figure 6. In addition to the images processed by random colours, the algorithm can detect the cane stem node from the original image and three kinds of data-enhanced images, which proved that the algorithm had a high accuracy. In Figure 6e, the lowest sugarcane stem node was over-exposed after random colour processing, so it could not be identified.  
Figure 5: Total loss function curve of model training.