# Channel Pruning-Based YOLOv7 Deep Learning Algorithm for Identifying Trolley Codes
## 2 Development of the Algorithm
### YOLOv7 Algorithm
#### 2.3.3 Pruning YOLOv7 Model  
Although the YOLOv7 model, which has been trained, demonstrates accurate identification of trolley codes, its extensive parameterization necessitates significant computational resources. We pruned the model in order to decrease the number of parameters and, consequently, its complexity. This was to enable deployment on devices with limited computational capabilities [26]. The channel pruning algorithm was employed to decrease the size and parameter count of the model by eliminating redundant parameters [27]. The simultaneous reduction in both the amount of necessary computation and the number of parameters is more advantageous compared to compression techniques that only decrease the number of parameters without affecting the actual number of model operations [28]. As depicted in Figure 8, the gamma coefficients of the Batch Normalization (BN) layer were employed in the channel pruning algorithm to assess the individual contributions of  
Figure 6: Curves depicting the training loss of the YOLOv7 model. The terms box_loss, obj_loss, cls_loss, and total_loss are denoted as (**a–d**), respectively. Figure 7: Results of identification of trolley codes by YOLOv7. (**a–d**) are samples 01111S, 0111, 01111L, and 01111N, respectively. the channels. Channels that made significant contributions (blue channels) were retained, while channels that made minimal contributions (orange channels) were eliminated. This decision was made by considering the distribution of the gamma coefficients and the rate at which the channel pruning algorithm pruned the channels. The steps of the channel pruning algorithm are as follows:  
1. In order to incorporate structural sparsity into the YOLOv7 model, the L1 regularization technique was utilized. Specifically, L1 regularization constraints were applied to the coefficients of the Batch Normalization (BN) layer within the YOLOv7 model. The objective of this phase was to fine-tune the model's parameters by imposing L1 regularization. 2. Following the initial training phase, we proceeded to implement channel pruning. This crucial procedure entailed the elimination of branches or channels within the YOLOv7 model, in accordance with a predetermined pruning ratio. The pruning ratio plays a crucial role in determining the proportion of channels that will be preserved, leading to a more streamlined and storage-efficient model. By selectively removing channels, we were able to substantially decrease the storage demands of the model, rendering it more manageable and appropriate for environments with limited resources. This particular step played a crucial role in optimizing the size of the model while simultaneously preserving its effectiveness. 3. Following the process of channel pruning, our foremost objective was to mitigate any potential decrease in accuracy. We conducted a meticulous fine-tuning process to carefully adjust and retrain the pruned model. Throughout the fine-tuning phase, we diligently balanced the parameters of the model to guarantee that, while achieving a reduction in size, we did not compromise significantly on accuracy. This step was undertaken with the objective of optimizing the pruned model, with a focus on achieving both compactness and performance, as both factors are of utmost importance. The total loss function of the channel pruning algorithm is shown in Equation (13):  
\[L=\sum_{(x,y)}l(f(x,W),y)+\lambda\sum_{\gamma\in\Gamma}g(\gamma) \tag{13}\]  
The first term on the right side of the equal sign is the loss function for network training; \(x\) and \(y\) are the training inputs and outputs, respectively. \(W\) is the training parameter of the network. The second term is the \(L_{1}\) regular constraint term for the gamma coefficient of the BN layer; and \(\lambda\) is the penalty factor. The parameter settings for the channel pruning process are shown in Table 3.  
Initially, sparse training was conducted, followed by the application of a pruning rate of 0.8 to eliminate channels from the YOLOv7 model.