Fast ship detection based on lightweight YOLOv5 network

IET Image ProcessingVolume 16, Issue 6 p. 1585-1593 ORIGINAL RESEARCH PAPEROpen Access Fast ship detection based on lightweight YOLOv5 network Jia-Chun Zheng, Corresponding Author Jia-Chun Zheng jchzheng@jmu.edu.cn School of Ocean Information Engineering, Jimei University, Xiamen, People's Republic of China Correspondence Jia-Chun Zheng, School of Ocean Information Engineering, Jimei University, Xiamen 361021, P. R. China. Email: jchzheng@jmu.edu.cnSearch for more papers by this authorShi-Dan Sun, Shi-Dan Sun orcid.org/0000-0001-7219-5933 School of Ocean Information Engineering, Jimei University, Xiamen, People's Republic of ChinaSearch for more papers by this authorShi-Jia Zhao, Shi-Jia Zhao School of Ocean Information Engineering, Jimei University, Xiamen, People's Republic of ChinaSearch for more papers by this author Jia-Chun Zheng, Corresponding Author Jia-Chun Zheng jchzheng@jmu.edu.cn School of Ocean Information Engineering, Jimei University, Xiamen, People's Republic of China Correspondence Jia-Chun Zheng, School of Ocean Information Engineering, Jimei University, Xiamen 361021, P. R. China. Email: jchzheng@jmu.edu.cnSearch for more papers by this authorShi-Dan Sun, Shi-Dan Sun orcid.org/0000-0001-7219-5933 School of Ocean Information Engineering, Jimei University, Xiamen, People's Republic of ChinaSearch for more papers by this authorShi-Jia Zhao, Shi-Jia Zhao School of Ocean Information Engineering, Jimei University, Xiamen, People's Republic of ChinaSearch for more papers by this author First published: 10 February 2022 https://doi.org/10.1049/ipr2.12432AboutSectionsPDF ToolsRequest permissionExport citationAdd to favoritesTrack citation ShareShare Give accessShare full text accessShare full-text accessPlease review our Terms and Conditions of Use and check box below to share full-text version of article.I have read and accept the Wiley Online Library Terms and Conditions of UseShareable LinkUse the link below to share a full-text version of this article with your friends and colleagues. Learn more.Copy URL Share a linkShare onFacebookTwitterLinked InRedditWechat Abstract Aiming at a series of problems such as detection accuracy, calculation blocking, display delay, and so on in the ship detection of surveillance video, an improved YOLOv5 algorithm is proposed in this paper. First, to improve the detection performance, it is proposed to optimize the anchor box algorithm in the YOLOv5 network according to the ship target characteristics. Then, the t-SNE algorithm is used to reduce and visualize the data set label information and perform weighted analysis on the processed features for low-dimensional data. The mapped kernel k-means clustering algorithm adaptively selects a more appropriate anchor box and considers the detection performance of large and small ship targets. Secondly, to improve the problem of computational blocking and delay, the BN scaling factor γ is used to compress the YOLOv5 network, so that the model can be reduced without reducing the detection performance. The optimized YOLOv5 framework is trained on the self-integrated data set. The accuracy of the algorithm is increased by 2.34%, and the ship detection speed reaches 98 fps and 20 fps in the server environment and the low computing power version (Jetson nano), respectively. 1 INTRODUCTION In recent years, marine ship monitoring has received more and more attention. The fast detection method of marine targets based on dynamic video is one of the key technologies to realize intelligent monitoring of sea areas. The commonly used detection methods can be divided into three categories in terms of sea surface targets. The first type of methods is the detection method of sea surface targets based on edge and texture features. Zhang et al. [1] used the DCT domain energy features of image sub-blocks to achieve fast extraction of sea level, establish a sea surface hybrid texture model, and achieve fast segmentation of sea surface background and ship targets. The second type of methods is to imitate the visual attention selection mechanism of human eyes and find the saliency map of the target of interest and achieve the detection of ship targets according to the established visual attention model. Shi et al. [2] first extracted the low-frequency and high-frequency features of the image in the wavelet domain, then used a modified Gabor filter to extract the directional features and extracted the colour and moment features in HIS space. Finally, they fused the above features to obtain the saliency map and detected ship targets. Shao et al. [3] proposed a convolutional neural network (CNN) based ship target detection algorithm, which uses CNN to predict the type and location of the target and assists in correcting the target localization using the saliency map, and the experimental results show that the method has high detection accuracy and speed. The third type of methods is the deep learning-based target detection algorithm for surface ships. Zhang et al. [4] proposed an integrated target segmentation method based on an interferer discriminator and a ship target extractor, first using SqueezeNet network as an interferer discriminator to determine what type of interference is contained in the input image, and then using the improved DeepLabv3+ depth network to segment the ship target. Experimental results show that the method has high segmentation accuracy and good fog resistance. Wang et al. [5] achieved fast end-to-end ship target detection with improved YOLOv3 (You Only Look Once) with 74.8% detection accuracy and 29.8 frames per second detection speed in GPU 1080Ti hardware environment. However, the current algorithm still has the following two problems: one is the low accuracy of small target detection. Second is most of the existing algorithms still cannot meet the needs of practical applications. In order to overcome the above problems, this paper compares different network frameworks [6-12], and finally selects YOLOv5 network as the basic framework. By improving the adaptive targeting frame algorithm, select a more appropriate anchor box, and optimize the network pruning to improve the performance of the algorithm. The contribution of this work can be summarized as follows: (1) In order to improve the detection accuracy, the t-SNE weighted clustering algorithm is proposed to be applied to the data processing process to realize the mapping of data to the high-dimensional space, and to perform accurate classification in the high-dimensional space to obtain more accurate prediction boxes; (2) In order to reduce the computational complexity of the algorithm, the BN scaling factor is further used to fine-tune the network channel to realize the lightweight algorithm; (3) The improved lightweight algorithm model can be deployed to the edge embedded equipment of the offshore target detection platform to realize real-time monitoring on the sea. The test results show that the detection accuracy of the improved algorithm is increased by 2.34%, and the detection speed can reach 20 fps on edge embedded devices. 2 INTRODUCTION TO THE BASIC PRINCIPLE OF YOLO NETWORK YOLO [13-16] is a single-stage target detection algorithm. With the development of YOLO, its detection accuracy and speed are gradually improving. YOLOv2 proposes a joint training algorithm, which improves the accuracy and speed of prediction. YOLOv3 joins the multi-scale network architecture in the FPN network [17]. It deepens the network backbone framework and improves the detection accuracy of the algorithm for multi-scale targets. YOLOv4 uses a large number of tricks to improve the detection accuracy of the algorithm as a whole. YOLOv5 slices the picture and adds CSPNet (Cross Stage Partial Networks) to the backbone network. YOLOv5 significantly reduces the skeleton of the network system. With its lightweight model size, the object recognition speed can be as high as 140 fps when running on the server. The network structure of YOLOv5 is shown in Figure 1. YOLOv5 is divided into four main parts, which are network input, feature extraction backbone, feature extraction parsing network and prediction module. The input uses three methods to enhance features: mosaic data enhancement, adaptive anchor frame calculation and adaptive image scaling. The purpose of mosaic data enhancement is to make the model better detect small objects in the image. The input data is sliced by focus before entering the backbone. The focus structure mainly expands the original image of three channels to 12. CSP structure reduces the parameters and size of the model from the perspective of network structure design. Neck enhances the network feature fusion for FPN + PAN structure, and uses a larger feature map to compensate for the loss of feature information at the top of feature pyramid. Prediction uses GIOU_Loss function, which is used to estimate the recognition loss of the detection target rectangle. Four kinds of network with different depth and width sizes are designed in YOLOv5, which are YOLOv5s, YOLOv5m, YOLOv5l and YOLOv5x. YOLOv5s is the smallest network framework of YOLOv5. When it runs on Titan RTX 2080 GPU, 78 frames can be processed per second, but if deployed on the Jetson nano embedded device for detection, the operation speed is only 4 fps, which cannot achieve the effect of real-time detection. To overcome this problem, this paper proposes an optimized kernel clustering and quantization compression YOLOv5 network structure method. The network structure is reduced by compression pruning to reduce the model size and runtime memory usage to overcome the problem that the ship cannot be detected in real time. FIGURE 1Open in figure viewerPowerPoint Structure of YOLOv5 3 OPTIMIZATION OF YOLOV5 ALGORITHM 3.1 Optimization of network structure As shown in the Figure 2, YOLOv5 has been optimized and improved based on data enhancement to improve detection accuracy and speed. The t-SNE is set to extract low-dimensional feature information in order to better handle the relevant data. The obtained low-dimensional data are sent into the weighted kernel function clustering to get a more accurate prediction target frame for a better prediction effect. The obtained data set are fed into the network training optimization, and the trained model is pruned using the BN scaling factor γ. The memory consumption at runtime is reduced and the number of computational operations is reduced without affecting the accuracy to facilitate the application of the model to removable devices. FIGURE 2Open in figure viewerPowerPoint Optimized framework 3.2 Optimization of clustering algorithm YOLOv5 optimizes the preprocessing of the data set. Auto learning bounding box anchors aim to get the preset anchor frame suitable for the predicting of the object bounding box in the custom data set. Adaptive anchor frame calculation is to update the target frame by updating the predicted frame area of each iteration. Because the accuracy of target detection is closely related to the setting of prediction box. The more accurate the prediction box, the higher the accuracy of its detection. t-SNE (t-Distributed Stochastic Neighbour Embedding) algorithm [18] is used to reduce the dimension of anchor frame prediction, and then combined with the weighted kernel clustering algorithm to predict the size of the frame. A more accurate prediction target frame is obtained, so as to achieve better prediction effect. t-SNE reduces high-dimensional data to two-dimensional or three-dimensional low dimensional space. t-SNE obtains the joint probability of high-dimensional data and low-dimensional mapping points through the symmetry of conditional probability, and minimizes KL divergence to reduce the difference of conditional probability distribution. t-SNE is developed from SNE (stochastic neighbour embedding). SNE maps data points to probability distribution by affine transformation, and uses Euclidean distance to express the similarity between points. Given a piece of N high-dimensional data. First, calculate the probability p j | i ${p_{j|i}}$ proportional to the similarity between data points x i ${x_i}$ and x j ${x_j}$ . Equation (1) represents the conditional probability of similarity expressed by high dimensional Euclidean distance. Parameter σ i ${\sigma _i}$ is based on data point x i ${x_i}$ is the center of Gaussian mean square error, here set to 1 / √ 2 $1/\surd 2$ . For low-dimensionality, the similarity between y i ${y_i}$ pairs can be expressed as Equation (2); p j | i = exp − ∥ x i − x j ∥ 2 / 2 σ i 2 ∑ k ≠ i exp − ∥ x i − x K ∥ 2 / 2 σ i 2 \begin{equation}{p_{j|i}} = \frac{{\exp \left( - \parallel {x_i} - {x_j}{\parallel ^2}/2\sigma _i^2\right)}}{{\mathop \sum \nolimits_{k \ne i} \exp \left( - \parallel {x_i} - {x_K}{\parallel ^2}/2\sigma _i^2\right)}}\end{equation} (1) q j | i = exp − ∥ y i − y j ∥ 2 ∑ k ≠ i exp − ∥ y i − y K ∥ 2 \begin{equation}{q_{j|i}} = \frac{{\exp \left( - \parallel {y_i} - {y_j}{\parallel ^2}\right)}}{{\mathop \sum \nolimits_{k \ne i} \exp \left( - \parallel {y_i} - {y_K}{\parallel ^2}\right)}}\end{equation} (2) Set the similarity probability of x i ${x_i}$ and y i ${y_i}$ to 0. The distance between the two probability distributions is the KL divergences (Kullback-Leibler divergences). Then the cost function is as shown in Equation (3). P i ${P_i}$ represents the conditional probability distribution of all other data points at a given point x i ${x_i}$ . When the dimensionality reduction effect is good, p(j|i) = q(j|i). C = ∑ i K L P i | Q i = ∑ i ∑ j p j | i log p j | i q j | i \begin{equation}C = \mathop \sum \limits_i KL\left( {{P_i}|{Q_i}} \right) = \mathop \sum \limits_i \mathop \sum \limits_j {p_{j|i}}\;\log \left\{ \frac{{{p_{j|i}}}}{{{q_{j|i}}}}\right\} \end{equation} (3) Analogous to the objective function gradient formula of softmax, the gradient of the conditional probability of i under j in the objective function of SNE is derived as 2 ( p i | j − q i | j ) ( y i − y j ) ${\rm{\;}}2( {{p_{i|j}} - {q_{i|j}}} )( {{y_i} - {y_j}} )$ . The gradient of the conditional probability of j under i is 2 ( p j | i − q j | i ) ( y i − y j ) $2( {{p_{j|i}} - {q_{j|i}}} )( {{y_i} - {y_j}} )$ . Finally, the complete gradient equation is as follows: σ C σ y i = 2 ∑ j ( p j | i − q j | i + p i | j − q i | j ) y i − y j \begin{equation}\frac{{\sigma C}}{{\sigma {y_i}}} = \;2\mathop \sum \limits_j ({p_{j|i}} - {q_{j|i}} + {p_{i|j}} - {q_{i|j}})\left( {{y_i} - {y_j}} \right)\end{equation} (4) t-SNE optimizes the congestion problem existing in SNE. It uses Gaussian distribution to convert the distance into a probability distribution. A distribution with a large distance probability is regarded as a joint probability distribution in a high-dimensional space, and a distribution with a small distance probability is a joint probability distribution in a low-dimensional space. In the low-dimensional space, the t-distribution is used to replace the Gaussian distribution to express the similarity of two points, reducing the impact of outliers, so as to better capture the overall characteristics of the data. The objective function can be rewritten as Equation (5): C = K L P i | Q i = ∑ i ∑ j p i , j log p i j q i j \begin{equation}C = KL\left( {{P_i}|{Q_i}} \right) = \mathop \sum \limits_i \mathop \sum \limits_j {p_{i,j}}\log \left\{ \frac{{{p_{ij}}}}{{{q_{ij}}}}\right\} \end{equation} (5) Equation (6) shows the change of q $q$ after using the t distribution. The t-distribution is the superposition of an infinitely many Gaussian distributions, which reduces amount of calculation. The optimized gradient is as shown in Equation (7): q i j = 1 + ∥ y i − y j ∥ 2 − 1 ∑ k ≠ l 1 + ∥ y i − y K ∥ 2 − 1 \begin{equation}\hspace*{-68pt}{q_{ij}} = \frac{{{{\left( {1 + \parallel {y_i} - {y_j}{\parallel ^2}} \right)}^{ - 1}}}}{{\mathop \sum \nolimits_{k \ne l} {{\left( {1 + \parallel {y_i} - {y_K}{\parallel ^2}} \right)}^{ - 1}}}}\end{equation} (6) σ C σ y i = 4 ∑ j ( p i j − q i j ) y i − y j 1 + ∥ y i − y j ∥ 2 − 1 \begin{equation}\frac{{\sigma C}}{{\sigma {y_i}}} = 4\mathop \sum \limits_j ({p_{ij}} - {q_{ij}})\left( {{y_i} - {y_j}} \right){\left( {1 + \parallel {y_i} - {y_j}{\parallel ^2}} \right)^{ - 1}}\end{equation} (7) For points with greater similarity, the distance of t-distribution in the low-dimensional space needs to be slightly smaller. For points with low similarity, the distance of t-distribution in the low-dimensional space needs to be farther. It meets the requirements of the target frame of the clustering algorithm after t-SNE dimensionality reduction. That is, the cluster points of different classes are separated from each other for classification. The clustering algorithm [19] processes the input data set to optimize the selection of the initial target frame within the network. The data set is classified by the size of the target frame, and the size of 9 a priori boxes is obtained. The size of the prior box is related to the scale. The smaller the prior frame is, the more detailed target edge information can be obtained when the scale is larger. This approach can cope with most datasets with a single data source and simple features, however, k-means clustering is biased for complex situations such as multiple data sources and differences in the effects of different attributes on different classes of features. In this regard, this paper adopts a weighted kernel clustering approach to cluster the data set. Kernel methods [20] map two-dimensional inputs to a high-dimensional feature space to classify categories. The sample features in the plane are mapped to the high-dimensional feature space as a way to accommodate the linear indistinguishability problem between different samples. After the classification is completed the mapping is returned to the two-dimensional plane to obtain the clustering results. Figure 2 shows the three-dimensional classification map after mapping. The weighted kernel k-means algorithm matches the importance of different features for different attributes, which makes the different feature ratios more balanced and results in a more accurate prediction frame. This kind of mapping is a non-linear transformation, which is conducive to the detection of unknown target frames. Equation (8) is the objective function definition of weighted kernel k-means, where i and a i ${a_i}$ represent the clustered pixels in the input space. w ( i ) $\;w( i )$ represents the weight of corresponding pixels. π k ${\pi _k}{\rm{\;}}$ represents the kth cluster. c k ${c_k}$ is the clustering centre of each subcategory. ϕ (AI) is the nonlinear mapping kernel distance function. J v = ∑ i = 1 k ∑ a i ∈ π k w i | | ϕ a i − c k | | 2 \begin{equation}J\left( v \right) = \mathop \sum \limits_{i = 1}^k \mathop \sum \limits_{{a_i} \in {\pi _k}} w\left( i \right)||\phi \left( {{a_i}} \right) - {c_k}|{|^2}\end{equation} (8) The calculation of non-linear kernel function is relatively difficult. From a mathematical point of view, there is a function K(x, x′) in a low dimensional space. When K(x, x′) = < φ (x) ⋅ φ (x′) > , it is exactly equal to the inner product in a high-dimensional space. The solution of the non-linear kernel function can be obtained by calculating the value of the sample points projected into the high-dimensional space and then performing the inner product operation. By calculating the inner product function of K(x, x′), the distance between the sample points and the centre of the cluster is obtained, which greatly reduces the difficulty of calculation. Equation (9) is the distance after K function simplification. Equation (10) is the cluster centre after operation. ϕ a i − c k | | 2 = ϕ a i · ϕ a i − 2 ∑ a j ∈ π k ϕ a i · ϕ a j π k + ∑ a j , a i ∈ π k ϕ a i · ϕ a j | π k | 2 \begin{eqnarray*} \left| {\left| {\phi \left( {{a_i}} \right) - {\rm{\;}}{c_k}|{|^2}}\right|}\right| &=& \phi \left( {{a_i}} \right) \cdot \phi \left( {{a_i}} \right) - \frac{{2\mathop \sum \nolimits_{{a_j} \in {\pi _k}} \phi \left( {{a_i}} \right) \cdot \phi \left( {{a_j}} \right)}}{{\left| {{\pi _k}} \right|}}\\ && + \frac{{\mathop \sum \nolimits_{{a_j},{a_i} \in {\pi _k}} \phi \left( {{a_i}} \right) \cdot \phi \left( {{a_j}} \right)}}{{|{\pi _k}{|^2}}} \end{eqnarray*} = K x , x ′ − 2 ∑ a j ∈ π k ϕ a i · ϕ a j π k + ∑ a j , a i ∈ π k ϕ a i · ϕ a j | π k | 2 \begin{eqnarray} \,\quad\qquad\qquad &=& K\left( {x,x^{\prime}} \right) - \frac{{2\mathop \sum \nolimits_{{a_j} \in {\pi _k}} \phi \left( {{a_i}} \right) \cdot \phi \left( {{a_j}} \right)}}{{\left| {{\pi _k}} \right|}}\nonumber\\ && +\, \frac{{\mathop \sum \nolimits_{{a_j},{a_i} \in {\pi _k}} \phi \left( {{a_i}} \right) \cdot \phi \left( {{a_j}} \right)}}{{|{\pi _k}{|^2}}} \end{eqnarray} (9) c k = ∑ a i ∈ π k w i ϕ a i ∑ a i ∈ π k w i \begin{equation}{c_k} = \frac{{\mathop \sum \nolimits_{{a_i} \in {\pi _k}} w\left( i \right)\phi \left( {{a_i}} \right)}}{{\mathop \sum \nolimits_{{a_i} \in {\pi _k}} w\left( i \right)}}\qquad\quad \end{equation} (10) The t-SNE method is used to reduce the dimensionality of the image feature matrix, and then whiten it. Finally, a matrix of N images (N, 256) is obtained. Weighted kernel clustering is used to get the image and its corresponding clustering. The clustering results are shown in Figure 3, which will act as pseudo tags, and the model will train on them. After analysing the data set of self-made ship by using the improved clustering algorithm, the size of 9 sets of prior frames is obtained. The comparison is shown in Table 1. The experimental results show that the optimized k-means algorithm has improved the detection effect. FIGURE 3Open in figure viewerPowerPoint Visualization results display TABLE 1. Comparison of back aiming frames in weighted kernel clustering Anchor box 52 × 52 26 × 26 13 × 13 Adaptive anchor frame (10, 13) (16, 30) (33, 23) (30, 61) (62, 45) (59, 119) (116, 90) (156, 198) (373, 326) Aiming frame after weighted sum clustering (8, 7) (10, 21) (15, 18) (27, 23) (77, 50) (61, 114) (115, 81) (224, 127) (354, 201) 3.3 Network layer model compression optimization To compress the YOLOv5 model, it is necessary to train the trained model sparsely. The purpose of sparse training is to identify the less important channels in the process of model training, so as to cut the less important channels. Sparsity is introduced to the dense connection of deep neural network, and the weight proportion with a small proportion is eliminated to reduce the network structure. After initializing the network, the channel sparse penalty is added to train the network. After deleting the channel, the fine-tuning network is trained. The channel sparseness method can reduce the size of the model, reduce the memory consumption at runtime, and reduce the number of calculation operations without affecting the accuracy. As shown in Figure 4, the BN scaling factor γ is used to prune the channels of the network. FIGURE 4Open in figure viewerPowerPoint Network layer model compression The scale factor in the batch normalization layer [21] is used as index of channel importance, L1 norm is calculated for the scale factor and trained in the loss function to obtain the importance score of each channel [22]. The update process of batch normalization layer is as follows. Equations (11) and (12) are the mean value and standard deviation of the output data of the upper layer, and m is the size of the batch of the training sample: μ β = 1 m ∑ z \begin{equation}{{{\mu}}_\beta } = \frac{1}{m}\;\sum z\end{equation} (11) σ β 2 = 1 m ∑ z − μ β 2 \begin{equation}\sigma\!\!\text{ }_{\beta }^{2}=\frac{1}{m}~\sum z-{{\text{ }\!\!\mu\!\!\text{ }}_{\beta }}{{}^{2}}\end{equation} (12) z ̂ = z i − μ B σ B 2 + ε \begin{equation}{{\hat z}} = \frac{{{{\rm{z}}_{\rm{i}}} - {{{\mu}}_{\rm{B}}}}}{{\sqrt {\sigma _B^2 + \varepsilon } }}\;\end{equation} (13) z = γ z ̂ + β \begin{equation}z = \gamma {{\hat z}} + \beta \end{equation} (14) Equation (13) is the result of normalization. ε is a value close to 0 added to avoid denominator being 0. Equation (14) is obtained by reconstructing the data obtained by the above normalization process. Among them, γ and β are learnable parameters, which are used to restore the normalized data distribution. The scaling factor γ in batch_norm is used to evaluate the importance of channel. The smaller the number of γ, the less important the channel information is. The channel can be deleted. In order to constrain the size of γ, a regular term about γ is added to the objective equation, which can be automatically pruned in training. But the previous model compression does not have. The L1 norm is calculated for the γ value of each channel. The specific calculation equation is as follows: L BN = λ γ 1 = λ ∑ γ \begin{equation}{{\rm{L}}_{{\rm{BN}}}} = \lambda \;{\left| {\left| \gamma \right|} \right|_1} = \lambda \sum \left| \gamma \right|\end{equation} (15) Finally, the loss function trained by the model adds a regularization term to the original loss function: L = L YOLO + L BN \begin{equation}{\rm{L}} = {{\rm{L}}_{{\rm{YOLO}}}} + {{\rm{L}}_{{\rm{BN}}}}\end{equation} (16) λ is the penalty term. After sparse training, a global threshold γ is introduced to decide whether to cut a feature channel. Prune the channels whose channel scale factor γ is less than the global threshold. At the same time, local security threshold δ is introduced to prevent over pruning on convolution layer and maintain the integrity of network connection. The local security threshold δ is the retention ratio of all channel scale factors in a specific layer. After channel pruning, the model is fine tuned to improve the detection accuracy of the pruned model. Figure 5 shows the total distribution of γ values for the 150th epoch of sparse training. It is obtained through experiments that λ = 0.001 is adopted for sparse training. When BN sparse regularization training is carried out after the normal training converges, the value of loss function first increases, and then γ value decreases with the increase of epoch number. FIGURE 5Open in figure viewerPowerPoint Total distribution of γ value of each epoch The final model of the network is obtained by choosing to prune off 45% of the parameters. The model size of YOLOv5x before compression is 92 MB, and the model size after compression is 47 MB, with an accuracy loss of 0.5%, which can be recovered by fine-tuning the network. See the experimental results section for its speed comparison. 4 ALGORITHMIC MODEL TRAINING 4.1 Experimental environment and plan The experimental environment is configured on ubuntu18.04 operating system, TITAN RTX 2080GPU, cuda10.1 and CUDNN, 128G memory platform, and pytorch1.2.0 framework is used for training. The pretraining model integrates 18,306 pieces of data from public data set and self-built data from the research team as the training target detection model. The training batch size selects 64 pictures, and the verification batch size selects 2 pictures. The initial learning rate is 0.0032. The cosine annealing strategy is used to reduce the learning rate gradually, but not less than 0.000001. The IOU threshold is 0.5, and the NMS threshold is 0.5. Back propagation is used to fine tune the network parameters. The data set is divided into training set and verification set for evaluation separately. The first 100 epochs optimize the network parameters of the last layer, and the second 200 epochs adjust the network parameters of the whole network. 4.2 Analysis of experimental results To evaluate the detection performance, we compared several representative methods: Fast R-CNN, SSD, eYOLOv3, s-CNN, with our improved YOLOv5x. Table 2 summarizes the detection results in terms of model volume, accuracy and speed. Model volume (MB) is the parametric size of the neural network, which reflects the complexity of the deep neural network to a certain extent. The AP index is related to the area under the exact recall curve and is used to measure the model detection accuracy. The FPS is used to evaluate the detection frame rate per second of the model. As can be seen from the table, the improved YOLOv5 detects frame rate of 45.97 in the server environment, and the size of the improved lightweight model reaches 47 MB, which is 32 MB smaller than the eYOLOv3 model size, and 18 MB smaller than the s-CNN model size, which is reflected in the frame rate of the improved model is 15 fps faster than eYOLOv3, and 5 fps faster than the s-CNN, the improved model has a better frame rate than other algorithms. And the accuracy of the improved model is 96.31%, which is 6.68% higher compared to the ssd algorithm and 4.61% higher compared to the more accurate s-CNN. This indicates that our method again improves the detection accuracy while enhancing the detection speed. It is beneficial for practical deployment. TABLE 2. Com