# Vehicle Distance Measurement Method of Two-Way Two-Lane Roads Based on Monocular Vision
## 2 Methods
### Establishment of Vehicle Detection Model of Two-Way Two-Lane Roads
#### 2.1.2 Training of Vehicle Detection Model Using YOLOv5s Network  
YOLOv5 is the fifth generation YOLO (you only look once) series of target detection methods proposed in 2020 and is the most advanced detection network in this series of algorithms [24]. Compared with other algorithms in the YOLO series, YOLOv5 has a smaller model size and faster training and image-processing speed. YOLOv5 has four network scales: s, m, l, and x. In addition, YOLOv5s has the smallest network depth and fast detection speed. Therefore, this paper selected the YOLOv5s network to train the vehicle detection model of two-way two-lane roads. The network structure of YOLOv5s is divided into four parts: input, backbone, neck, and prediction. Its network structure is shown in Figure 3.  
The basic component of the network is CBL, which is composed of a convolution layer (Conv), batch normalization layer (batch normalization, BN), and activation function (Leaky ReLU). At the input of the network, images are preprocessed, and the mosaic data enhancement method is used to randomly scale, cut, arrange, and then splice them to improve the detection effect of small targets. In addition, the adaptive anchor box calculation function is also applied to adaptively calculate the value of the optimal anchor box in different training sets during each training [25]. The backbone network is used to extract image features. First, the Focus structure is used to slice images to reduce the number of network layers, effectively alleviating the problem of gradient disappearance [26]. The input image of 640 \(\times\) 640 \(\times\) 3 first becomes a feature map of 320 \(\times\) 320 \(\times\) 12 after the slicing operation, and it finally becomes a feature map of 320 \(\times\) 320 \(\times\) 32 after a convolution operation of 32 convolution kernels. Then, referring to the design idea of the cross-stage partial network (CSP Net), two kinds of CSP structures corresponding to CSP1_X in the backbone and CSP2_X in the neck are designed to optimize the problem of excessive computation caused by repeated gradient information [27]. These CSP structures divide  
Figure 3: Network structure of YOLOv5s. Figure 2: Presentation of data sets. (**a**) Partial sample of data sets; (**b**) Example of annotation. the feature map of the basic layer into two branches for convolution operation and finally use the Concat function to merge the two branches. At the end of the backbone network, the spatial pyramid pooling networks (SPP Net) are applied; they realize the fusion of local features and global features by using three parallel max pooling layers (Maxpool) to down-sample the feature map. The neck is used to further improve the ability of feature extraction; it combines the two structures of the feature pyramid network (FPN), which conveys the high-level feature information in a top-to-bottom manner, and the path aggregation network (PAN), which conveys strong positioning characteristics in a bottom-to-top manner to realize the fusion of features of different scales and enable the model to obtain richer feature information. In the prediction layer, the optimal target frame is filtered by combining the loss function GIOU and the non-maximum suppression (NMS) algorithm [28]. In order to evaluate the performance of the trained model, precision (\(P\)), recall (\(R\)), average precision (\(AP\)), and mean average precision (\(mAP\)) were used as evaluation indicators. \(P\) represents the proportion of the number of targets correctly detected to the number of all targets detected. \(R\) represents the proportion of the number of targets correctly detected to the number of all actual targets. They were respectively defined as follows [29]:  
\[P=\frac{TP}{TP+FP}\times 100\%, \tag{1}\]  
\[R=\frac{TP}{TP+FN}\times 100\%, \tag{2}\]  
where \(TP\) represents the number of targets that are correctly detected, \(FP\) represents the number of non-targets that are detected as targets, and \(FN\) represents the number of targets that are detected as non-targets.