# Channel Pruning-Based YOLOv7 Deep Learning Algorithm for Identifying Trolley Codes
## 2 Development of the Algorithm
### YOLOv7 Algorithm
#### 2.3.2 Identifying Trolley Codes Based on YOLOv7
Throughout the training procedure, it was observed that the training speed was relatively sluggish, the utilization of memory resources was not substantial, and the loss function exhibited significant fluctuations. According to the Batch Size Doubling Strategy, the batch size was adjusted to 32. The GPU's parallel performance was fully utilized, resulting in a significant acceleration of the model's training speed and a notable reduction in the fluctuation of the loss function. In order to enhance the training process and identify the most suitable batch size, we made an adjustment to the batch size, setting it to 64. However, the training was unsuccessful due to limited memory resources. After conducting a series of experiments, we determined that the optimal batch size for training is 32. This decision was influenced by the specific characteristics of the dataset's images and the GPU's capabilities, in order to achieve the most favorable training outcome. The parameters of YOLOv7 used in this study are presented in Table 2. \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter** & **Value** \\ \hline Image size & 640 \(\times\) 640 \\ Learning rate & 0.001 \\ Batch & 32 \\ Number of categories & 2 \\ Number of iterations & 300 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Parameters of the YOLOv7 model. Figure 5: YOLOv7-based identification of trolley codes. In terms of loss function, YOLOv7 is similar to YOLOv5. As shown in Equation (5), YOLOv7 is divided into classification loss (_cls_loss_), bounding box position loss (_box_loss_), and confidence loss (_obj_loss_). \[Ltotal\_loss=Lobj\_loss+Lbox\_loss+Lcls\_loss \tag{5}\]  
Confidence loss and classification loss use BCE cross-entropy loss. The calculation formula of BCE cross-entropy loss is displayed as Equations (6) and (7), where \(\sigma(x_{n})\) represents the sigmoid function, \(w_{n}\) represents the average of the results, and \(y_{n}\) represents the real sample label. \[L_{n}=-w_{n}[y_{n}\cdot\log\sigma(x_{n})+(1-y_{n})\cdot\log(1-\sigma(x_{n}))] \tag{6}\]  
\[\sigma(x_{n})=\frac{1}{1+e^{-x}} \tag{7}\]  
The bounding box position loss adopts CIoU loss, and the calculation formula is represented by Equations (8)-(12), where \(A\) represents the predicted frame, \(B\) represents the real frame, \(\alpha\) is the weight function, and \(\
u\) is used to measure the consistency of the aspect ratio. \(w^{st}\) and \(hs^{st}\) are the width and height of the ground truth bounding box, while \(w\) and \(h\) represent the width and height of the predicted bounding box. \(\rho^{2}\big{(}b,bs^{st}\big{)}\) is the center point distance between two bounding boxes, and \(c\) is the diagonal distance of a bounding box that can at least enclose the two bounding boxes. \[I_{oU}=\frac{|A\cap B|}{|A\cup B|} \tag{8}\]  
\[\alpha=\frac{\
u}{1-I_{oU}+\
u} \tag{9}\]  
\[\
u=\frac{4}{\pi^{2}}\bigg{(}arctan\frac{w^{st}}{hs^{st}}-arctan\frac{w}{h} \bigg{)}^{2} \tag{10}\]  
\[CIoU=I_{oU}-\frac{\rho^{2}\big{(}b,bs^{st}\big{)}}{c^{2}}+\alpha\
u \tag{11}\]  
\[L_{box\_loss}=1-CIoU \tag{12}\]  
Figure 6 illustrates the loss curves for _box_loss_, _obj_loss_, _cls_loss_, and _total_loss_ throughout the training process. After 300 iterations, the values of _box_loss_, _obj_loss_, _cls_loss_, and _total_loss_ were 0.006604, 0.003979, 0.0002599, and 0.01084, respectively. It is evident from the analysis of Figure 6 that the model demonstrated efficient learning capabilities, as indicated by the rapid convergence of the training curves during the initial stage of training. As the training advanced, the rate of change of the curve gradually diminished. The learning efficiency of the model reached a plateau after 50 iterations. The outcomes of trolley code identification using the YOLOv7 algorithm, which has been trained, are depicted in Figure 5:0 The algorithm demonstrated the capability to precisely detect both small holes and big holes in the images of samples 01111N, 01111L, 01111S, and 0111. This step establishes the foundation for the process of model pruning.