# Visual SLAM Mapping Based on YOLOv5 in Dynamic Scenes
## 2 Method Introduction
### Adaptive Anchor Frame Calculation  
The initial Anchor can be set in the dataset, and when the network is trained, the training network outputs the prediction frame based on the Anchor, and the loss can be calculated by comparing it with the ground truth frame; after the loss is obtained, the network is updated with feedback, and the network parameters are updated by iterating through each layer of the network. The initial anchor points in YOLOv3 [35] and YOLOv4 [36] can be set using a specific K-means algorithm setup procedure. However, the Anchor of the YOLOv5 network differs from the above two versions in that the Anchor is written directly into the overall code of the network in the YOLOv5 network, and the optimal anchor frame values of the YOLOv5 network are calculated adaptively each time the dataset is used for training. In the Neck layer of YOLOv4, all the structures required for its operation need to be combined with the convolutional network. In contrast, the CSP2_X structure designed by the Content Security Policy network (CSPnet) is used in the Neck layer of YOLOv5, which makes the YOLOv5 network more capable of fusing features, as shown in Figure 3b. Figure 2: Structure principle of the YOLO algorithm. As shown in Figure 3, compared with the Neck of YOLOv4, the Neck of YOLOv5 uses a different convolution network on some modules. The Neck layer in YOLOv5 consists of five convolutional network modules combined. The five convolutional network modules are the Conv and BN and Leaky ReLU (CBL) module, the Spatial Pyramid Pooling (SPP) module, the CSP2-1 module, the Upsampling (UP) module, and the Concat module. The functions and roles of each module are as follows:  
1. CBL module: The CBL module is mainly composed of the most basic convolution modules, i.e., Conv, Batch normalization (BN), and Leaky ReLU. Its main function is the convolution of the input image and extraction of image features, and it is often used in the convolution layer of image convolution processing in target detection. 2. SPP module: The SPP module mainly solves the problem of frame loss during image clipping and scaling, and it enables the convolutional neural network to extract features many times, which improves the speed of generating candidate boxes. In YOLOv5, the feature image is mainly pooled. 3. CSP2-1 module: the gradient value of backpropagation between layers can be increased by increasing the residual structure, which avoids the disappearance of the gradient caused by the deepening of the network, so that more fine-grained features can be extracted and so that we do not have to worry about network degradation. It is mainly used in the backbone of the YOLOv5 network. 4. UP module: the main function of the UP module is to pool the feature image from the CBL convolution layer so that the size of the input feature image is increased and the size of the feature image is consistent. 5. Concat module: the input feature images are fused to better highlight the features of target detection. To make the calculation result more accurate, YOLOv5's Central Input/Output Unit (_CIOU_) not only adds the distance between the target object and the anchor frame to the calculation result, but also adds the coverage and penalty class to it, so it will not fail to converge as YOLOv4's _CIOU_ did in the training process. The _CIOU_ formula is as follows:  
\[CIOU=IOU-\frac{\rho^{2}\big{(}b,b^{gt}\big{)}}{c^{2}}-\alpha\
u \tag{1}\]  
where \(\rho^{2}(b,b^{gt})\) represents the Euclidean length of the prediction frame and the center of the real frame shape, respectively; \(c\) is the diagonal length of the prediction frame and the rear frame together forming the range; and \(\alpha\) and \(\
u\) are given by the following equations:  
\[\alpha=\frac{\
u}{1-IOU+\
u} \tag{2}\]  
Figure 3: (**a**) Neck structure of YOLOv4; (**b**) Neck structure of YOLOv5.