# An Accelerating Method of YOLOv7 Based on Lightweight Network Architecture
## 2 Related Works  
### YOLOv7  
YOLOv7 is a one-stage deep neural network model for object detection. Compared to the two-stage Faster R-CNN series detection models [7], YOLOv7 achieves a better balance between detection speed and accuracy. The backbone network structure of YOLOv7 is shown in Figure 1.  
The backbone network of the YOLO series models extracts features from images at different levels. In the YOLOv7 backbone network, C1, C2, and C3 are obtained as downsampled feature maps at 8\(\times\), 16\(\times\), and 32\(\times\), respectively. Among these, C1 represents the shallow features of the image, which contain more spatial information about the target, while C3 represents the deep features, which contain more semantic information. After feature extraction by the backbone network, YOLOv7 uses the PaFPN (Path Aggregation Feature Pyramid Network) structure and coupled heads to output the predicted values of the target.  
The predicted output of YOLOv7 includes the values for four prediction boxes, category prediction values, and target confidence values (x, y, w, h, c).  
The loss function consists of three components: the offset of the predicted box, IoU (Intersection over Union) and confidence loss, and category loss.  
Equation (1) is the loss value of the prediction box:  
\[l_{bbox}=\sum_{i=0}^{K\times K}\sum_{j=0}^{M}l_{i,j}^{obj}(2-w_{i}\times h_{i} )\begin{bmatrix}-x_{i}log(\hat{x_{i}})-(1-x_{i})log(1-\hat{x_{i}})\\ -y_{i}log(\hat{y_{i}})-(1-y_{i})log(1-\hat{y_{i}})\\ +(w_{i}-\hat{w_{i}})^{2}+\left(h_{i}-\hat{h_{i}}\right)^{2}\end{bmatrix} \tag{1}\]  
In Equation (1), \(\hat{x_{i}},\hat{y_{i}},\hat{w_{i}},\hat{h_{i}}\) represents the predicted value and \(x_{i},y_{i},w_{i},h_{i}\) represents the true label value. \(l_{i,j}^{obj}\) is the Indicator Function, \(K\) represents the grid size, and \(M\) represents the number of anchors per grid.  
Equation (2) is the category loss:  
\[l_{cls}=-\sum_{i=0}^{K\times K}\sum_{j=0}^{M}l_{i,j}^{obj}\sum_{c\in classes} \begin{bmatrix}(1-p_{i}(c))log(1-\hat{p_{i}}(c))\\ +p_{i}(c)log(\hat{p_{i}}(c))\end{bmatrix} \tag{2}\]  
In Equation (2), \(\hat{p_{i}}(c)\) represents the predicted category probability value and \(p_{i}(c)\) represents the true label value.  
Figure 1: Schematic diagram of YOLOv7 backbone network structure.  
Equation (3) is the confidence loss:  
\[\begin{array}{l}l_{obj}=-\sum\limits_{i=0}^{K\times K}\sum\limits_{j=0}^{M} \Gamma_{i,j}^{obj}\left[C_{i}log\left(\hat{C_{i}}\right)+(1-C_{i})log\left(1- \hat{C_{i}}\right)\right]\\ -\sum\limits_{i=0}^{K\times K}\sum\limits_{j=0}^{M}\Gamma_{i,j}^{noobj}\left[C_ {i}log\left(\hat{C_{i}}\right)+(1-C_{i})log\left(1-\hat{C_{i}}\right)\right] \end{array} \tag{3}\]  
In Equation (3), \(\hat{C_{i}}\) represents the predicted confidence value and \(C_{i}\) represents the true label value.  
The loss function value of YOLOv7 is obtained by summing three parts, as shown in Equation (4):  
\[loss=l_{bbox}+l_{cls}+l_{obj} \tag{4}\]  
The loss function represents the distance between the predicted values of the network and the true target values. Using the loss function as a feedback signal, the loss is backpropagated through an optimizer to update the weights of each layer and train the network. The training process of the neural network model is shown in Figure 2.