Improved YOLOv7-tin canopy electric vehicle detection method
By introducing the Trible module and Biformer attention mechanism in the YOLOv7-tiny model, replacing PAnet with Bifpn, and using SIoU loss function and SPPCSPC module, the detection problem of YOLOv7-tiny in complex backgrounds and high traffic flow situations is solved, and the detection problem of YOLOv7-tiny in complex backgrounds and high traffic flow situations is improved. The detection accuracy and speed achieve accurate identification and automated detection of electric vehicle awnings.
Patent Information
- Application Number
- CN202411078063.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2025-01-10
AI Technical Summary
YOLOv7-tiny has poor detection results under complex backgrounds and high traffic flow conditions, and is prone to missed detection and missed detection, especially for insufficient detection accuracy and speed for small targets.
Improve the YOLOv7-tiny model, introduce the Trible module and Biformer attention mechanism, replace PAnet with Bifpn, and use the SIoU loss function and the SPPCSPC module to optimize the network structure to improve detection accuracy and speed.
It improves detection accuracy and convergence speed, and can more accurately identify whether electric vehicles are equipped with canopies, realize automated detection, and reduce the incidence of traffic accidents.
Smart Images

Figure CN119295888A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of computer vision, and in particular relates to an improved YOLOv-tiny rain shed electric vehicle detection method. Background Art
[0002] With the development of deep learning, all walks of life have gradually introduced intelligent detection and applied deep learning to the detection of parasols for illegally modified electric vehicles. The method combined with deep learning not only speeds up the detection speed, but also improves the detection efficiency, while saving a lot of manpower costs. This technology has been widely used in real life. Therefore, it has become a top priority to establish a detection algorithm based on deep learning to identify illegally modified electric vehicles.
[0003] This algorithm can quickly and accurately detect illegal modification behaviors and provide a powerful tool for traffic management and law enforcement departments. Through the application of deep learning technology, we can better cope with the challenges brought by illegal modification of electric vehicles. At present, there are two main algorithms for target detection in deep learning: one is the one-stage target detection algorithm, including YOLO, SSD, etc., and the second is the two-stage target detection algorithm, such as Mask R-CNN. The two-stage algorithm has more advantages in detection accuracy than the single-stage algorithm, with higher accuracy. Compared with the single-stage algorithm, it has more advantages in speed. As the mainstream single-stage framework, YOLO is obviously more advantageous when there is heavy traffic and fast target movement.
[0004] The YOLOv-tiny algorithm is a variant of YOLOv7. It is fast and suitable for practical scenarios. However, YOLOv7-tiny has poor detection effect in complex backgrounds. The detection effect of YOLOv7-tiny grid is not ideal when facing large flow of people and vehicles. Some false detections may occur. For some slightly smaller targets, false detections and missed detections may also occur. Summary of the invention
[0005] The purpose of the present invention is to solve the defects of the above-mentioned prior art and propose an improved YOLOv7-tiny canopy electric vehicle detection method.
[0006] The present invention adopts the following technical solution:
[0007] An improved YOLOv7-tiny canopy electric vehicle detection method includes the following steps:
[0008] Step 1. Collect the canopy electric vehicle dataset, first annotate it in labelimg, and then perform data augmentation to expand the data.
[0009] Step 2. Select the YOLOv7-tiny model
[0010] Step 3. Improve the YOLOv7-tiny model, introduce the Trible module in the Backbone of the model, introduce the Biformer attention mechanism in the Neck part, replace the PAnet of the original framework with Bifpn, replace the loss function SIoU, and finally use the SPPCSPC module in series.
[0011] Step 4. Train the improved YOLOv7-tiny model in step 3, set the maximum iteration rounds to 200, and the learning rate to 0.098 to train the final model.
[0012] Step 5. Use the trained model to detect the data in step 1.
[0013] The YOLOv7-tiny model in step 2 includes:
[0014] The YOLOv7-tiny network is mainly composed of an input module (Input), a backbone network (Backbone), a neck (Neck) and a head (Head).
[0015] The input image is resized to the default 640×640 size and then enters Backbone. Backbone passes the extracted features to the Neck layer and finally outputs the prediction results through the Head layer.
[0016] Among them, the Backbone of YOLOv7-tiny is mainly composed of ELAN module and CBL module. Backbone is also the feature extractor of YOLOv7-tiny, in which each CBL module is composed of convolution layer, normalization layer and activation function. The ELAN module is composed of several CBL modules. The features extracted by the ELAN module are passed to the Neck part.
[0017] The Neck part uses the PAnet structure to fuse the features of each layer to detect targets of different types and scales. The Neck part is mainly composed of the CBL module and the ELAN module. The SPPCSPC module connects Backone and Neck. The SPPCSPC is also connected to the ELAN module. The SPPCSPC module consists of several CBL modules and 3 Maxpools.
[0018] The head part uses ordinary convolution instead of REP convolution. Compared with the YOLOv7 framework, the accuracy is indeed reduced, but it has advantages in speed and model size. The function of the head is to predict the input image and output three different prediction results.
[0019] SIoU loss function in step 3:
[0020] The SIoU loss function consists of four parts: angle loss (Angle cost), distance loss (Distancecost), shape loss (Shape cost), and IoU loss (IoU cost).
[0021] The angle cost formula is as follows:
[0022]
[0023] where c h is the vertical height difference between the center of the predicted box and the center of the actual box; σ is the distance between the center of the predicted box and the center of the actual box:
[0024]
[0025] When α is 90° or 0°, the angle loss is 0.
[0026] The distance cost formula is as follows:
[0027] Δ=Σ t=x,y (1-e -γρt ) (5)
[0028]
[0029] ρ x It is to calculate the relative distance between the predicted box and the actual box on the x-axis, c w Represents the minimum enclosing rectangle of the real box.
[0030]
[0031] ρ y It is to calculate the relative distance between the predicted box and the real box on the y-axis;
[0032] γ=2-Λ (8)
[0033] γ is a coefficient used to adjust ρ x , ρ y The degree of influence on the overall loss function;
[0034] When α approaches 0, the contribution of Distance cost is greatly reduced.
[0035] As α gets closer The greater the distance cost.
[0036] Shape cost formula is as follows:
[0037]
[0038]
[0039] ω w Indicates the relative difference between the widths of two bounding boxes.
[0040]
[0041] ω h Represents the relative difference between the heights of two bounding boxes;
[0042] (w,h) represents the width and height of the prediction box, (w gt ,h gt ) represents the width and height of the real box. In order to avoid paying too much attention to the shape loss and reducing the movement of the predicted box, it is necessary to adjust θ to change the emphasis on the shape loss.
[0043] IoU cost is as follows:
[0044]
[0045] The final loss can be expressed by the formula
[0046]
[0047] Δ represents distance cost, Ω represents shape cost, L box Represents the final loss.
[0048] Biformer attention mechanism in step 3:
[0049] For an input two-dimensional feature map, it is divided into non-overlapping regions, each of which includes a feature vector, where C is the number of channels and k is the number of regions that need to be paid attention to. So the total amount of calculation formula is as follows:
[0050]
[0051] when The inequality holds.
[0052] W represents width, H represents height, C represents the number of channels, k represents the number of regions that need to be paid attention to, and S represents the region division factor.
[0053] The SPPCSPC module in step 3 is:
[0054] SPPCSPC is composed of convolution and maximum pooling. It extracts features through multiple convolution layers, integrates features through the serial MP layers, and performs concat operations through convolution and convolution of another channel.
[0055] Bifpn module in step 3:
[0056] A learning parameter tensor is set with an initial value of 1. This parameter is used to weight the input of two feature maps. By using the epsilon function, division by 0 is avoided during normalization. A 1x1 convolution is used to adjust the number of channels, and the SiLU activation function is used to introduce nonlinearity.
[0057] The Trible module in step 3 is:
[0058] It mainly consists of three branches: global average pooling branch, horizontal and vertical average pooling branch. First, the spatial dimension (height and width) of the input feature is reduced to 1 through global average pooling (nn.AdaptiveAvgPool2d(1)) to obtain the global information of the entire feature map.
[0059] This step enables the module to capture the average importance of each channel in the entire feature map.
[0060] In order to obtain more spatial direction information, Trible also performs average pooling in the horizontal and vertical directions. Through nn.AdaptiveAvgPool2d((None,1)) and nn.AdaptiveAvgPool2d((1,None)), it performs average pooling on the feature map in the horizontal and vertical directions respectively.
[0061] These operations enable the module to focus on the globally distributed features in the feature map in the horizontal and vertical directions. In this way, Trible not only integrates information from different spatial directions, but also effectively enhances the expressiveness of the channel dimension of the input feature map by learning the adjusted weights. This method enables the network to pay more attention to important feature channels while suppressing less important channels, thereby improving the performance and accuracy of the overall model.
[0062] Beneficial effects of the present invention:
[0063] This paper uses the excellent target detection capability and excellent detection speed of YOLOv7-tiny, improves the detection accuracy and convergence speed by improving the loss function and adding the attention mechanism. At the same time, combined with the attention mechanism, the detection capability of the Trible and other modules is enhanced, which can detect in real time whether the electric vehicle in the image is equipped with a canopy, and realize automatic detection.
[0064] The research results of this invention can be applied to various scenarios, such as traffic arteries, parking lots, roadsides, etc., to achieve automated awning detection and reduce the incidence of traffic accidents. The algorithm can provide strong support for awning recognition, which is of great significance for public transportation. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] Figure 1 It is a flow chart of the steps of the present invention.
[0066] Figure 2 This is the YOLOv7-tiny algorithm flow chart.
[0067] Figure 3 This is the algorithm flow chart of the SPPCSPC module.
[0068] Figure 4 This is a comparison chart between Bifpn and PAnet.
[0069] Figure 5 This is the flowchart of the Trible algorithm.
[0070] Figure 6 Improved framework diagram for YOLOv7-tiny.
[0071] Figure 7 This is a comparison chart before and after P improvement.
[0072] Figure 8 Comparison chart before and after mAP@0.5 improvement.
[0073] Figure 9(a) is the original image for detection, and (a)-(e) are the extracted images.
[0074] Figure 9(b) is a detection diagram of the effect of the YOLOv7-tiny algorithm; (a)-(e) are pictures detected using the YOLOv7-tiny algorithm.
[0075] Figure 9(c) is a detection diagram of the effect of the YOLOv7-tiny-SC algorithm; (a)-(e) are pictures detected using the YOLOv7-tiny-SC algorithm. DETAILED DESCRIPTION
[0076] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention is described clearly and completely below. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0077] The operating environment of the present invention: configure the conda environment on the Ubuntu system, and install Pytorch 1.13 and CUDA 11.6 versions.
[0078] like Figure 1 As shown, an improved YOLOv7-tiny canopy electric vehicle detection method includes the following steps:
[0079] Step 1. Collect the canopy electric vehicle dataset, first annotate it in labelimg, and then perform data augmentation to expand the data.
[0080] Step 2. Select the YOLOv7-tiny model
[0081] Step 3. Improve the YOLOv7-tiny model, introduce the Trible module in the Backbone of the model, introduce the Biformer attention mechanism in the Neck part, replace the PAnet of the original framework with Bifpn, replace the loss function SIoU, and finally use the SPPCSPC module in series.
[0082] Step 4. Train the improved YOLOv7-tiny model in step 3, set the maximum iteration round to 200, and the learning rate to 0.098 to train the final model.
[0083] Step 5. Use the trained model to perform data detection in step 1.
[0084] Among them, the YOLOv7-tiny model in step 2 includes:
[0085] The YOLOv7-tiny network is mainly composed of an input module (Input), a backbone network (Backone), a neck (Neck) and a head (Head), such as Figure 2 shown.
[0086] First, the input image is resized to the default 640×640 size and then enters Backbone. Backbone passes the extracted features to the Neck layer and finally outputs the prediction results through the Head layer.
[0087] Among them, the Backbone of YOLOv7-tiny is mainly composed of ELAN modules and CBL modules. Backbone is also the feature extractor of YOLOv7-tiny, in which each CBL module consists of a convolution layer, a normalization layer, and an activation function. The ELAN module is composed of several CBL modules. These modules are designed to extract features from images. The features extracted by the ELAN module are passed to the Neck part. ELAN refers to Conv, batch normalization layer, and LeakyReLU.
[0088] The Neck part uses the PAnet structure to fuse the features of each layer to detect targets of different types and scales. The Neck part is mainly composed of the CBL module and the ELAN module. The SPPCSPC module connects Backone and Neck. SPPCSPC is also connected to the ELAN module. It can be used to learn more feature information, which not only improves the speed but also improves the model learning ability. The SPPCSPC module consists of several CBL modules and 3 Maxpools.
[0089] The head part uses ordinary convolution instead of REP convolution. Compared with the YOLOv7 framework, the accuracy is indeed lower, but it has advantages in speed and model size. The function of the head is to predict the input image and output three different prediction results. The head includes 3 CBL modules.
[0090] Among them, the SIoU loss function in step 3 is:
[0091] The loss function of YOLOv7-tiny does not take into account the problem of mismatch between the object to be detected and the target box, and the amount of calculation is large, and the gradient may disappear. The SIoU loss function is based on the angle between the regression vectors, and it locates the position by redefining the penalty index. Therefore, it can be used as a positioning loss function.
[0092] The SIoU loss function consists of four parts: angle cost, distance cost, shape cost, and IoU cost. These parts are designed to better measure the positioning error in target detection.
[0093] The angle cost formula is as follows:
[0094]
[0095] Among them, Λ means Angle Cost, is the coordinate of the center point of the real frame, Indicates the center coordinate of the prediction box, c h is the vertical height difference between the center of the predicted box and the center of the actual box; σ is the distance between the center of the predicted box and the center of the actual box:
[0096]
[0097] When α is 90° or 0°, the angle loss is 0.
[0098] The distance cost formula is as follows:
[0099] Δ=Σ t=x,y (1-e -γρt ) (5)
[0100]
[0101] ρ x It is to calculate the relative distance between the predicted box and the actual box on the x-axis, c w Represents the minimum enclosing rectangle of the real box.
[0102]
[0103] ρ y It is to calculate the relative distance between the predicted box and the real box on the y-axis.
[0104] γ=2-Λ (8)
[0105] γ is a coefficient used to adjust ρ x , ρ y The degree of influence on the overall loss function.
[0106] When α approaches 0, the contribution of Distance cost is greatly reduced.
[0107] As α gets closer The greater the distance cost.
[0108] Shape cost formula is as follows:
[0109]
[0110] θ represents the control of the attention paid to the shape loss.
[0111]
[0112] ω w Indicates the relative difference between the widths of two bounding boxes.
[0113]
[0114] ω h Indicates the relative difference between the heights of two bounding boxes.
[0115] (w,h) represents the width and height of the prediction box, (w gt ,h gt ) represents the width and height of the real box. In order to avoid paying too much attention to the shape loss and reducing the movement of the predicted box, it is necessary to adjust θ to change the emphasis on the shape loss.
[0116] IoU cost is as follows:
[0117]
[0118] A represents the true box, B represents the predicted box, A∩B represents the area of the intersection of the true box and the predicted box, and A∪B represents the area of the true box and the predicted box minus the area of their intersection.
[0119] The final loss can be expressed by the formula
[0120]
[0121] Δ represents distance cost, Ω represents shape cost, L box Represents the final loss.
[0122] Among them, the Biformer attention mechanism in step 3:
[0123] Biformer is a sparsity-aware dynamic attention. Its novelty lies in dynamically adjusting the input features to better adapt to targets of different sizes. This approach enables Biformer to maintain good performance when handling dense prediction tasks and achieve high computational efficiency. Biformer is a variant of the Transformer model, which is a dynamic attention mechanism added to the original Transformer model. This mechanism uses a two-layer routing mechanism (BRA) to achieve flexible and efficient computational allocation, making the model dynamic query-aware and sparsity-aware. First, for a query, irrelevant key values are filtered out at the coarse region level, and then fine-grained token-to-token attention is applied to the combination of the remaining candidate regions (routing regions), which uses sparsity to save computational memory and only involves GPU-friendly dense matrix algorithms to accelerate the inference process. In order to solve the problem of being able to use fine-grained token-to-token attention in each region, it uses a directed graph. The purpose is to assign each region to which it should be connected. For each query token, it uses an index mechanism to guide the attention calculation through routing information. The final BRA calculation includes linear projection, regional path calculation, and token to token calculation. For an input two-dimensional feature map, it is divided into non-overlapping regions, each of which includes a feature vector, where C is the number of channels and k is the number of regions to be concerned. So the total calculation formula is as follows:
[0124]
[0125] when The inequality holds.
[0126] H and W mean height and width respectively, C means the number of channels, k means the number of regions that need to be paid attention to, and S represents the region division factor.
[0127] Among them, the SPPCSPC module in step 3 is:
[0128] The main function of the SPP module is to enhance the model's detection and expression capabilities for multi-scale targets in target detection tasks. SPP is mainly used to solve the scale invariance problem in target detection. In traditional convolutional neural networks, fixed-size pooling operations are usually used, which leads to the network losing some key information on targets of different scales. CSP is mainly used to optimize the information transfer and computational efficiency of deep neural networks. It divides the feature map into two parts, then applies a convolution operation on one part, and then connects the result to the other part to reduce information loss and gradient vanishing while maintaining the computational efficiency of the model. It optimizes the feature extraction process by combining SPP and CSP techniques, so that the network can more effectively capture the feature information of targets of different scales. And the information transfer efficiency and computational efficiency of the model are improved by segmentation and connection. This combination enables the model to perform better when dealing with complex scenes and multi-scale targets. The specific structure is as follows Figure 3 As shown in Figure 2, the SPPCSPC model can reduce feature loss, improve feature extraction capabilities, and enhance detection performance while increasing the number of parameters through series connection.
[0129] SPPCSPC is mainly composed of convolution and maximum pooling. It extracts features through multiple convolution layers, and then through the serial MP layer, it can effectively extract the features in the feature map, which is conducive to better subsequent recognition of the network. Then, it integrates the features through the concat operation, which helps the network to learn. Then, through the convolution and the convolution of another channel, the concat operation is performed to effectively fuse the features, which can improve the information exchange of the network and improve the network's expression ability.
[0130] Among them, the Bifpn module in step 3:
[0131] The Neck part of the framework consists of a pyramid network structure PAnet, which aims to fuse input features of different scales. Although PAnet treats different input features in the same way during feature fusion, in fact, different inputs may have different features for the final output. For some complex traffic environments, the target is small due to excessive speed, resulting in missed detection. In order to achieve a higher level of feature fusion and strengthen the fusion and transmission of multi-scale target features, Bifpn is used to replace PAnet. Bifpn deletes nodes with only one edge at both ends and introduces bidirectional connections between different levels in the middle. These connections allow feature information to flow between different levels. To help improve the flow between different scales and levels, Bifpn also introduces training weights to adjust the contribution of different inputs to the feature map. The original Bifpn uses weighted average fusion to fuse features. In order to better capture and fuse high-level features, the weighted average feature fusion method is changed to average feature fusion. Compared with weighted feature fusion, average feature fusion is more direct, reduces the noise and overfitting in model feature fusion, effectively emphasizes the important features of the object, and combines the improved Bifpn with the original Bifpn to adapt to different input features, mine deep information, and enhance the network's detection ability for targets of different scales.
[0132] The network structure diagram of PAnet and Bifpn is as follows Figure 4 As shown in the figure, there are 5 layers in total. The blue line goes from top to bottom, through this channel, high-level features can be fused upwards, the yellow part goes from bottom to top, through this path, low-level features can flow to high-level features, and for the middle line, its function is to fuse more features and realize the fusion of different features.
[0133] The Bifpn network mainly sets a learnable parameter tensor with an initial value of 1. This parameter is used to weight the input of two feature maps. (If there are 3 features to be fused, the input here is 3). By using the epsilon function, the division by 0 is avoided during the normalization process. Then, a 1x1 convolution is used to adjust the number of channels. The SiLU activation function is used to introduce nonlinearity, in order to enable the neural network to represent and learn more mapping relationships.
[0134] The Trible module in step 3 is:
[0135] The Trible module mainly solves the problem of unbalanced feature representation of each channel in the neural network. In a convolutional neural network, different channels may have different response capabilities to different features. Some channels may be more critical to the recognition task, while other channels may be redundant or irrelevant. The core idea of Triple is to enhance the response to important features and suppress the response to irrelevant features by learning the importance weight of each channel, thereby improving the network's expressiveness and performance.
[0136] It mainly consists of three branches: global average pooling branch, horizontal and vertical average pooling branch. Figure 5 As shown, first, the spatial dimensions (height and width) of the input features are reduced to 1 through global average pooling global_pooling to obtain the global information of the entire feature map. This step enables the module to capture the average importance of each channel in the entire feature map. In order to obtain more spatial direction information, Trible also performs average pooling in the horizontal and vertical directions. Through nn.AdaptiveAvgPool2d((None,1)) and nn.AdaptiveAvgPool2d((1,None)), it performs average pooling on the feature map in the horizontal and vertical directions respectively. These operations enable the module to focus on the global distribution features in the feature map in the horizontal and vertical directions.
[0137] It has the following main advantages: context fusion, feature recalibration, and adaptive weighting. Context fusion enables Trible to fuse global and local context information through pooling layers in different directions, so that the network can better understand the overall and details of the scene, and thus make more accurate judgments. Secondly, feature recalibration enables the Trible module to learn which features are more important to the final task after training, and then highlight these features by adjusting the channel weights to improve the accuracy of recognition or classification. Finally, adaptive weighting is performed dynamically through channel reweighting, and automatically adjusted according to different inputs. This adaptability makes the model more robust when processing variable inputs.
[0138] In short, the improved model is renamed YOLOv7-tiny-SC Figure 6 As shown in the figure, by adding Trible to Backbone, the model can capture more key features. Replacing the PAnet structure in the original text with the Bifpn structure can change the information flow. Introducing Biformer attention in the Head of the framework can extract deeper information, thereby improving the performance of target detection. Using the SIoU loss function can more accurately predict the position and shape of the target box and accelerate the convergence speed.
[0139] Experimentation and Evaluation
[0140] Experimental dataset and environment
[0141] Since there is no relevant data set at present, in order to conduct relevant research. The present invention uses a mobile phone to take a picture of illegal modification of electric vehicles. The data set is expanded to 6146 pictures through data enhancement and annotated by labelimg. The data set generates training sets and validation sets in a ratio of 7:3. The present invention uses precision (Precision), recall (Recall), and average precision to mAP (mean Average Precision). Among them, P is the number of true positive samples in the predicted positive samples; R is the number of positive samples retrieved in the overall positive sample model; mAP is mAP@0.5 and mAP@0.5:0.95 respectively, mAP@0.5 is the intersection and union ratio of the real box and the predicted box, and mAP@0.5:0.95 is the mAP on IoU between 0.5 and 0.95. All indicators range from 0 to 1, and the larger the value, the better the detection effect of the model.
[0142] Experimental software environment: Ubuntu 18.04 operating system, deep learning framework using Pytorch version and CUDA 11.6 version
[0143] Hardware environment: 12th Gen Inter Core i5-12400 2.5GHz processor, NVIDIA GeForce RTX3060 graphics card
[0144] Experimental evaluation indicators
[0145] The present invention uses precision, recall, and mean average precision (mAP). Among them, P is the number of true positive samples in the predicted positive samples; R is the number of positive samples retrieved in the overall positive sample model; mAP is mAP@0.5 and mAP@0.5:0.95 respectively, mAP@0.5 is the intersection-over-union ratio of the real box and the predicted box, and mAP@0.5:0.95 is the mAP on IoU 0.5 to 0.95. All indicators range from 0 to 1, and the larger the value, the better the detection effect of the model.
[0146] The formula refers to the following:
[0147]
[0148] In the above formula, P represents the ratio of the number of correctly detected illegally modified electric vehicles to the number of detected illegally modified electric vehicles. R represents the recall rate, which is the ratio of the number of correctly detected illegally modified electric vehicles to the number of illegally modified electric vehicles in the data set. FP represents the number of illegally modified electric vehicles that were misdetected, and FN represents the number of non-illegally modified electric vehicles that were misdetected. N represents the number of detection categories, and AP represents the precision of the i-th category. TP refers to the number of target objects correctly identified by the model. This experiment has only one category.
[0149] Experimental results analysis
[0150] In order to better verify the effectiveness of the algorithm of the present invention, Biformer blocks are added to the model, the loss function and Trible modules are changed, etc. The improved name module is named YOLOv7-tiny-SC. By combining various improvements, the model has better results in precision, recall and mAP. Figure 7 It is a comparison chart of P with Epoch rounds. It can be seen from the figure that the accuracy of model training is higher than that of the model before modification, which means that the improved model is stronger than the original model in both feature extraction and feature fusion. Figure 8 This is the result of the intersection and union with an IoU threshold of 0.5. It can be seen from the figure that after the model training is stable, the accuracy of the modified model is higher than that of the original model, which can directly reflect the performance of the model in detection.
[0151] Detection effect analysis
[0152] under Figure 9(a)-Figure 9(c) The original image and the effect detection diagram of the YOLOv7-tiny algorithm and the YOLOv7-tiny-SC algorithm. For some close-range targets, the YOLOv7-tiny-SC algorithm has higher accuracy than the original algorithm. For some long-range small and medium-sized targets, the original YOLOv-tiny will miss detection or have low accuracy, while the YOLOv7-tiny-SC algorithm also has a good effect on the detection of some small and medium-sized targets. For some complex and background interference, the original model will have misdetection, and the improved model solves this problem. By comparison, it can be seen that the YOLOv7-tiny-SC algorithm is stronger than the original algorithm in the case of small and medium-sized targets or background interference.
[0153] Ablation experiment
[0154] In order to better verify the efficiency of the algorithm of the present invention, ablation experiments were conducted, and a total of 6 groups of experiments were conducted. The above-mentioned data set was also used for testing, epcoh was set to 200, "√" indicates that the module is used, and "×" indicates that the module is not used. The evaluation of the experimental model is shown in the table. It can be seen from Table 1 that the accuracy and average accuracy are improved after adding the Biformer attention mechanism and the feature pyramid Bifpn and SPPCSPC. Through the attention mechanism and the feature pyramid structure framework, more detailed features can be extracted to better identify the object to be tested. Through the Trible module, more useful information is extracted in the feature extraction stage, which can well solve the problem that some small target information cannot be recognized, and effectively improve the detection accuracy of the model.
[0155] Table 1 Ablation experiment results
[0156]
[0157] Comparative experiment
[0158] In addition, the present invention also compares the improved model with other classic target detection models, and selects three performance indicators of accurate mAP@0.5 and mAP@0.5:0.95 for comparison. The data is shown in Table 2. As can be seen from the table, the YOLOV9 algorithm has the highest accuracy. In addition to YOLOV9, the average accuracy of the improved YOLOv7-tiny-SC model is the highest compared to all other models. Analyze the reason: After adding the attention mechanism, the model can pay more attention to important features. It helps to improve the average accuracy of the model under various thresholds. By adding Trible to the feature extraction layer, the extraction ability of small targets is affected, the recognition of small targets is enhanced, and mAP is effectively improved. Because objects of different sizes are evaluated separately when calculating mAP, the main reason why YOLOv9 is higher than the method of the present invention is that the number of parameters of the YOLOV9 algorithm is nearly one-sixth higher than the algorithm of the present invention, and the detection speed is also slower than the algorithm. Considering the actual situation, it is necessary to ensure the accuracy of the algorithm and the speed of detection. The algorithm of the present invention is the best in terms of comprehensive consideration.
[0159] Table 2 Comparative experimental results
[0160]
[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An improved YOLOv7-tiny canopy electric vehicle detection method, characterized in that: The steps include: Step 1. Collect the canopy electric vehicle dataset, first annotate it in labelimg, and then perform data augmentation to expand the data; Step 2. Select the YOLOv7-tiny model. Step 3. Improve the YOLOv7-tiny model, introduce the Trible module in the Backbone of the model, introduce the Biformer attention mechanism in the Neck part, replace the PAnet of the original framework with Bifpn, and replace the loss function SIoU, and finally use the SPPCSPC module in series; Step 4. Perform model training, set the maximum iteration round to 200, set the learning rate to 0.098, and train the final model; Step 5. Use the trained model to detect the data in step 1.
2. The method according to claim 1, characterized in that The YOLOv7-tiny model in step 2 includes: The network of YOLOv7-tiny consists of input module, backbone network, neck and head; The working process is as follows: the input image is adjusted to the default 640×640 size, and then enters the Backbone, which passes the extracted features to the Neck layer, and finally outputs the prediction results through the Head layer; Among them, the Backbone of YOLOv7-tiny consists of ELAN module and CBL module. Backbone is also the feature extractor of YOLOv7-tiny. Each CBL module consists of convolution layer, normalization layer and activation function. The ELAN module is composed of several CBL modules. The features extracted by the ELAN module are passed to the Neck part. The Neck part uses the PAnet structure to fuse the features of each layer to detect targets of different types and scales. The Neck part is composed of a CBL module and an ELAN module. The SPPCSPC module connects Backone and Neck. The SPPCSPC is also connected to the ELAN module. The SPPCSPC module is composed of several CBL modules and 3 Maxpools. The Head part uses ordinary convolution instead of REP convolution. The function of the Head is to predict the input image and output three different prediction results.
3. The method according to claim 1, characterized in that SIoU loss function in step 3: The SIoU loss function consists of four parts: Angle cost, Distance cost, Shape cost, and IoU cost; The angle cost formula is as follows: Among them, Λ means Angle Cost, is the coordinate of the center point of the real frame, Indicates the center coordinates of the prediction box, c h is the vertical height difference between the center of the predicted box and the center of the actual box; σ is the distance between the center of the predicted box and the center of the actual box: When α is 90° or 0°, the angle loss is 0; The distance cost formula is as follows: Δ=∑ t=x,y (1-e -γρt ) (5) in ρ x It is to calculate the relative distance between the predicted box and the actual box on the x-axis, c w Represents the minimum enclosing rectangle of the real box; ρ y It is to calculate the relative distance between the predicted box and the real box on the y-axis; γ=2-Λ (8) γ is a coefficient used to adjust ρ x , ρ y The degree of influence on the overall loss function; When α approaches 0, the contribution of Distance cost is greatly reduced; As α gets closer The larger the Distancne cost; The shape cost formula is as follows: ω w Represents the relative difference between the widths of two bounding boxes; ω h Represents the relative difference between the heights of two bounding boxes; (w,h) represents the width and height of the prediction box, (w gt ,h gt ) represents the width and height of the real box. In order to avoid paying too much attention to the shape loss and reducing the movement of the predicted box, it is necessary to adjust θ to change the emphasis on the shape loss; IoU cost is as follows: The final loss is expressed by the formula Δ represents distance cost, Ω represents shape cost, L box The ultimate loss.
4. The method according to claim 1, characterized in that: Biformer attention mechanism in step 3: For an input two-dimensional feature map, it is divided into non-overlapping regions, each of which includes a feature vector, where C is the number of channels and k is the number of regions that need to be paid attention to, so the total calculation amount formula is as follows: when The inequality holds; W represents width, H represents height, C represents the number of channels, k represents the number of regions that need to be paid attention to, and S represents the region division factor.
5. The method according to claim 1, characterized in that The SPPCSPC module in step 3 is: SPPCSPC is composed of convolution and maximum pooling. It extracts features through multiple convolution layers, integrates features through the serial MP layers, and performs concat operations through convolution and convolution of another channel.
6. The method according to claim 1, characterized in that Bifpn module in step 3: A learning parameter tensor is set with an initial value of 1. This parameter is used to weight the input of two feature maps. By using the epsilon function, division by 0 is avoided during normalization. A 1x1 convolution is used to adjust the number of channels, and the SiLU activation function is used to introduce nonlinearity.
7. The method according to claim 1, characterized in that The Trible module in step 3 is: It consists of three branches: global average pooling branch, horizontal and vertical average pooling branches. First, the spatial dimension of the input feature is reduced to 1 through global average pooling to obtain the global information of the entire feature map; In order to obtain more spatial direction information, Trible also performs average pooling in the horizontal and vertical directions. Through nn.AdaptiveAvgPool2d((None,1)) and nn.AdaptiveAvgPool2d((1,None)), it performs average pooling on the feature map in the horizontal and vertical directions respectively.