A dangerous chemical vehicle target detection method based on improved YOLOv7-tiny
By introducing the C2fGhostv2 network and PConv module into the YOLOv7-tiny model and combining it with the WIoU loss function, the model structure was optimized, solving the problems of low detection accuracy and deployment difficulties. This enabled efficient detection of hazardous chemical vehicles, suitable for complex backgrounds and mobile devices.
Patent Information
- Application Number
- CN202311303447.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-09
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2043-10-09
AI Technical Summary
The existing YOLOv7-tiny model has low detection accuracy in the detection of hazardous chemical vehicles and is difficult to deploy to end devices. It cannot effectively cope with the interference of complex backgrounds and scale changes.
The C2fGhostv2 network and PConv module are introduced into the YOLOv7-tiny model. Combined with the WIoU loss function, the backbone and neck structure of the model are optimized for lightweight improvement. Furthermore, the dataset is enhanced by mosaic technology to improve detection accuracy and robustness.
It improves the detection accuracy and robustness of the model in complex backgrounds, realizes lightweight hazardous chemical vehicle detection, and is suitable for mobile devices.
Smart Images

Figure CN117315584B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of hazardous chemical vehicle detection and identification, and in particular to a target detection method for hazardous chemical vehicles based on an improved YOLOv7-tiny. Background Technology
[0002] With rapid economic development, my country's volume of hazardous materials transportation, including energy, raw materials, and consumer goods, is increasing significantly. In 2007, the daily transport volume of hazardous chemicals exceeded 1 million tons, with an annual total exceeding 400 million tons. Due to the widespread production and use of hazardous chemicals, their transportation has become a crucial economic activity. Hazardous chemical vehicles play a key role in various sectors, including industry and transportation. As the number of hazardous chemical vehicles on the road continues to increase, the need for their safety management and monitoring is becoming increasingly urgent. However, hazardous chemical vehicles pose risks during transportation, such as fires, explosions, and leaks of hazardous substances, which can cause toxic and corrosive hazards to human health and the environment. Furthermore, handling emergencies involving hazardous chemical vehicles presents challenges and poses a potential threat to traffic safety. Therefore, real-time monitoring of hazardous chemical vehicles is of significant research importance.
[0003] With the continuous development of artificial intelligence technology, deep learning-based target detection algorithms have made significant progress and are gradually being widely applied. However, in road transportation, the accuracy of hazardous chemical vehicle detection is affected by a variety of factors. For example, hazardous chemical vehicles typically operate in complex environments, where various interfering objects may exist in the background, interfering with target detection and localization. Secondly, the size and shape of hazardous chemical vehicles may vary depending on the vehicle type, the cargo, and other factors; such scale variations can affect the accuracy and robustness of detection algorithms. Furthermore, occlusion and partial visibility are also common problems. Hazardous chemical vehicles may be occluded by other objects or the scene, and some targets may only be partially visible, all of which affect the completeness and accuracy of the target, posing challenges to detection algorithms. Therefore, addressing these influencing factors is key to improving the accuracy and robustness of hazardous chemical vehicle detection. Summary of the Invention
[0004] Purpose of the Invention: For the target detection task of hazardous chemical vehicles, YOLOv7-tiny has some limitations, such as low detection accuracy and difficulty in deployment on end devices. Therefore, this invention proposes a hazardous chemical vehicle target detection method based on an improved YOLOv7-tiny, which makes a series of improvements to YOLOv7-tiny to improve detection accuracy and achieve model lightweighting.
[0005] Technical solution: This invention discloses a target detection method for hazardous chemical vehicles based on the improved YOLOv7-tiny, comprising the following steps:
[0006] S1. Obtain the image to be processed and preprocess it; First, process the original images in the hazardous chemical vehicle dataset to generate images of uniform size, and then process the images of uniform size a second time.
[0007] S2. Construct a hazardous chemical vehicle target detection model based on YOLOv7-tiny. In the backbone part of the model, introduce a C2fGhostv2 network and a PConv module. The C2fGhostv2 network is composed of a GhostNetv2 network and a C2f module. The GhostNetv2 network is composed of a Ghost module and a decoupled fully connected attention mechanism (DFC). The GhostNetv2 network replaces multiple repeated residual blocks in the C2f module, achieving lightweight feature extraction and long-range dependency capture. Specifically, C2fGhostv2 is introduced between the first and second max pooling operations in the backbone part to replace the original XBL module there. PConv is used to replace some ordinary convolutions in the last two XBL modules in the backbone to obtain PXBL.
[0008] S3. Introduce a lightweight C2fGhostv2 network into the Neck part of the YOLOv7-tiny target detection model; replace the last XBL module in the original model before predicting large-scale targets with the C2fGhostv2 network to further process the feature maps passed from the backbone network.
[0009] S4. Use the WIoU loss function to balance the training effect of the samples;
[0010] S5. The Head part of the network model receives multi-scale feature maps from the Neck part, and generates the location and category information of the target box through convolution and decoding operations. The image processed in step S1 is input into the hazardous chemical vehicle detection network for training. The weights of the trained hazardous chemical vehicle detection network are saved to generate a lightweight hazardous chemical vehicle detection model for detecting hazardous chemical vehicles.
[0011] Furthermore, the specific steps of step S1 are as follows:
[0012] S1.1 Input the images of hazardous chemical vehicles into the model to generate images of uniform size;
[0013] S1.2. Mosaic technology is used to enhance the original data. The input hazardous chemical vehicle image is divided into small blocks and recombined to achieve image transformation. Each small block is translated, scaled, cropped, stitched, and its hue, brightness, and saturation are changed. After being stitched together, a new image is generated, thus obtaining the hazardous chemical vehicle dataset.
[0014] Furthermore, the specific steps of step S2 are as follows:
[0015] S2.1 Input the preprocessed image into the Backbone part of the network model;
[0016] S2.2 The input image undergoes a series of convolutional layers and pooling layers to extract local features from the input image.
[0017] S2.3. C2fGhostv2 is introduced between the first and second max pooling operations in the backbone part of the model, replacing the XBL module there.
[0018] For input features X∈R H×W×C_in First, the data stream enters the first 1×1 convolution of the C2fGhostv2 module, and then enters two branches: the main branch C1 and the secondary branch W1. The main branch C1 first performs a split operation to divide the data stream into two branches C2 and W2. C2 is used as input to enter the GhostNetv2 network, which is then fed into the Ghost module and the decoupled fully connected attention mechanism DFC. The Ghost module generates output feature C3, and the decoupled fully connected attention mechanism DFC generates attention matrix M. The Sigmoid function is used to restrict the output of the attention matrix to the range [0,1]. The dot product of the two branches is then used to obtain output feature C4.
[0019] C4 is processed by the Ghost module to generate feature C5. Then, the output C5 is concatenated with C2 to obtain the total output feature Y1 of the GhostNetv2 part; Y1∈R H×W×0.5C_in The various branches, namely the outputs Y1 and W1-Wn, are concatted to obtain C_out. Finally, a 1×1 convolution is performed to reduce the dimensionality of the features to their original size, resulting in the final output Y2∈R. H×W×C_out ;
[0020] S2.4 After step S2.3, the features of the image are extracted and enhanced. Next, the PConv module is introduced into the backbone part of the model to replace the partial ordinary convolution of the last two XBL modules in the backbone part, so that the model can make more effective use of the information in the feature map.
[0021] S2.5 Finally, a series of feature maps are output, each corresponding to an image region of a different scale.
[0022] Furthermore, the specific steps of step S3 are as follows:
[0023] S3.1 Input the features after passing through the backbone into the Neck of the network model to further process the feature maps passed from the backbone network in order to extract richer semantic information;
[0024] S3.2 The extracted features are fused from feature maps at different levels using a feature pyramid network;
[0025] S3.3 After the feature pyramid is created, the Neck section uses convolution or upsampling operations to fuse features;
[0026] S3.4 The Neck section also introduces the C2fGhostv2 module, replacing the last XBL module in the original model before predicting large-scale targets with the C2fGhostv2 network. Finally, the Neck section outputs shallow feature maps, medium feature maps and deep feature maps respectively, which are used to detect the location and category of the target.
[0027] Furthermore, the WIoU loss function in step S4 is specifically as follows:
[0028] S4.1 The definition of the WIoU loss function is as follows:
[0029] L WIoUv1 =R WIoU L IoU (5)
[0030]
[0031] Among them W g H g The minimum bounding box size is used to prevent R from being... WIoU This generates a gradient that hinders convergence; the superscript * indicates that W... g H g Separate from the computation graph.
[0032] Furthermore, the specific steps of step S5 are as follows:
[0033] S5.1 Input the fused features into the Head part of the network model to perform target detection of hazardous chemical vehicles;
[0034] S5.2. The position and category information of the target box are generated through convolution and decoding operations. Output decoding is the process of converting the convolution output into the actual target box on the image. The anchor box information is used to parse and scale the convolution output to obtain the coordinates of the target box.
[0035] S5.3 After output decoding, use NMS to remove highly overlapping redundant target boxes, retain only the most reliable detection box for each target, and obtain the final detection result.
[0036] Beneficial effects:
[0037] To address the issues of low detection accuracy and large parameter count in traditional models, which hinder end-user deployment, this invention introduces the lightweight network C2fGhostv2 to improve the backbone and neck of the YOLOv7-tiny network. This enables the model to capture the dependencies between pixels at long-distance spatial locations of hazardous chemical vehicles in complex backgrounds, thereby improving detection accuracy. The fast and efficient PConv is introduced into the backbone to reduce computational redundancy and memory access, resulting in higher efficiency and feature extraction capabilities. Furthermore, WIoU is used to address the degradation in target localization performance caused by blindly emphasizing high-quality samples, further enhancing the model's detection capabilities. Experimental results show that the proposed model achieves both high detection accuracy and lightweight design, with a high average accuracy, showing improvement over the original YOLOv7-tiny model. This effectively improves the model's detection performance, computational efficiency, robustness, and generalization performance. The hazardous chemical vehicle target detection algorithm described in this invention has broad application prospects and provides strong support for vehicle detection in the industrial field. Attached Figure Description
[0038] Figure 1 This is a flowchart of the method of the present invention;
[0039] Figure 2 A schematic diagram for improving the model;
[0040] Figure 3 This is a network diagram for C2fGhostv2.
[0041] Figure 4 This is a schematic diagram of the Ghost module;
[0042] Figure 5 This is a schematic diagram of the DFC attention mechanism;
[0043] Figure 6 This is a comparison chart of ordinary convolution and partial convolution. Detailed Implementation
[0044] The present invention will be further illustrated below with reference to the accompanying drawings and specific embodiments. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. After reading this invention, any modifications of the invention in various equivalent forms by those skilled in the art fall within the scope defined by the appended claims.
[0045] As attached Figure 1 As shown, this invention discloses a target detection method for hazardous chemical vehicles based on the improved YOLOv7-tiny, the specific steps of which are as follows:
[0046] S1. Image Preprocessing. First, the original images in the hazardous chemical vehicle dataset are processed to generate images of uniform size. Then, these uniform-sized images are processed a second time.
[0047] S1.1 Input the images of hazardous chemical vehicles into the model to generate images of uniform size.
[0048] S1.2 Next, mosaic technology is used to enhance the original data. The input hazardous chemical vehicle image is divided into small blocks and recombined to transform the image. Each block undergoes operations such as translation, scaling, cropping, stitching, and changes in hue, brightness, and saturation. These blocks are then stitched together to generate a new image, thus obtaining the hazardous chemical vehicle dataset. This operation simulates visual changes in the real world, such as object rotation, scaling, and translation, allowing the model to obtain more information from the original image and improving its generalization ability in different scenarios.
[0049] S2. Construct a hazardous chemical vehicle target detection model based on YOLOv7-tiny. Introduce C2fGhostv2 between the first and second max-pooling operations in the backbone of the model, replacing the original XBL module there. Also, replace some ordinary convolutions in the last two XBL modules in the backbone with PConv. This effectively improves the model's computational efficiency and feature extraction capabilities, facilitating the extraction of more effective features from images.
[0050] S2.1 Input the preprocessed image into the Backbone part of the network model.
[0051] S2.2 The input image undergoes a series of operations such as convolutional layers and pooling layers to extract local features from the input.
[0052] S2.3. Introduce C2fGhostv2 between the first and second max-pooling operations in the Backbone section, replacing the XBL module there. C2fGhostv2 is constructed using a GhostNetv2 network and C2f modules, as shown below. Figure 3 As shown.
[0053] First, the GhostNetv2 network, consisting of Ghost modules and a decoupled fully connected attention mechanism (DFC), achieves lightweight feature extraction and capture of long-distance dependencies, thereby effectively enhancing the model's detection capabilities in complex backgrounds.
[0054] For Ghost modules (such as...) Figure 4 As shown), given input features X∈R H×W×CThe Ghost module splits the output channel into two parts. First, a regular convolution is performed to obtain a portion of the feature map, and then a simple linear transformation (γ) is applied. k This process generates features, resulting in another feature map. Finally, the outputs from both parts are concatenated to obtain the final output. The calculation formula is as follows:
[0055] Y′=X*F 11 (1)
[0056] Y = Concat(Y′, Y′*F) d (2)
[0057] For decoupling fully connected attention mechanisms (such as...) Figure 5 As shown), first, given the input Z∈R H×W×C If we consider them as H×W tokens, then Z∈{Z 11 Z 12 ,...,Z HW Then, it is decomposed into two fully connected layers along the horizontal and vertical directions, respectively, to model long-distance features in the corresponding directions. This decomposition can increase the model's ability to perceive long-distance dependencies. The specific formula is as follows:
[0058]
[0059]
[0060] Where F W and F H For learnable weights, α h ′ w α represents the attention output along the vertical direction. hw This represents the fusion of attention outputs along the horizontal and vertical directions, i.e., the complete attention output. The DFC attention mechanism can be obtained from the above equation.
[0061] For input X∈R H×W×C The inputs are fed into the Ghost branch and the DFC Attention branch, respectively. The Ghost branch generates the output feature Y according to equations (1) and (2), and the DFC Attention branch generates the attention matrix M according to equations (3) and (4). The output of the attention matrix is restricted to the range [0,1] using the Sigmoid function. Finally, the two branches are multiplied to obtain the final output.
[0062] Output = sigmoid(M) * w(X) (5)
[0063] Secondly, C2f first applies the input X∈R H×W×CPerform a 1x1 convolution, then split the result into two parts. One part is directly connected to the output, and the other part is processed through multiple repeated residual blocks (Bottleneck). Finally, concatenate all these parts and pass them through another 1x1 convolution to obtain the final output. These processes can obtain richer gradient flow information while ensuring lightweight operation.
[0064] Finally, the C2fGhostv2 module merges the GhostNetv2 network and the C2f module, replacing the repeated residual blocks (Bottleneck) of the C2f module with the GhostNetv2 network. The specific operation of the C2fGhostv2 module is as follows: for input features X∈R... H×W×C_in First, the data stream enters the first 1×1 convolution of the C2fGhostv2 module, and then enters two branches: the main branch C1 and the secondary branch W1. The main branch C1 first performs a split operation to divide the data stream into two branches, C2 and W2. C2 is then used as input to enter the GhostNetv2 network, feeding into the Ghost branch and the DFC Attention branch, respectively. The Ghost branch generates output feature C3, while the DFC Attention branch generates an attention matrix M. The Sigmoid function is used to constrain the output of the attention matrix to the range [0,1]. The dot product of the two branches yields output feature C4. Next, C4 is processed by the Ghost model to generate feature C5. Finally, the output C5 is concatenated with C2 to obtain the total output feature Y1 of the GhostNetv2 part. At this point, Y1∈R H×W×0.5C_in Perform a concat operation on each branch (output Y1 and W1-Wn) to obtain C_out, where C_out ∈ R. H×W×0.5(n+2)C_in Finally, a 1×1 convolution is performed to reduce the dimensionality of the features to their original size, resulting in the final output Y2∈R. H×W×C_out By performing the above operations, the model can provide richer feature representations while maintaining its lightweight nature, thereby improving its detection performance in complex backgrounds.
[0065] S2.4 After step S2.3, the image features are extracted and enhanced. Next, the PConv module is introduced into the backbone of the model to replace some of the ordinary convolutions in the last two XBL modules of the backbone. The PConv module, as a partial convolution operation, differs from traditional convolutions in terms of spatial feature extraction. A comparison is shown in the figure below. Figure 6 As shown. In traditional convolution, for input X∈R C×H×W(C represents the number of channels, H represents the height, and W represents the width), the output is obtained directly through convolution operation, resulting in O∈R. C×H×W Partial convolution operates in two branches for each input X∈R. C×H×W Part of it is obtained by performing traditional convolution operations, resulting in the output of the first branch. To achieve coherent or regular memory access, the first or last consecutive c channels are used as representatives of the entire feature map for computation, while keeping some channels unchanged. This reduces computational and memory access overhead, resulting in the output of the second branch. This leads to the final output O∈R C×H×W This approach can more effectively utilize the information in the feature map, further improving the model's feature representation ability and detection accuracy.
[0066] S2.5 Finally, a series of feature maps are output, each corresponding to an image region of different scales. These feature maps contain rich semantic information and will be used in subsequent steps of hazardous chemical vehicle detection.
[0067] S3. Introduce the C2fGhostv2 network in the Neck part of the model to replace the last XBL module in the original model before predicting large-scale targets. This allows the model to obtain richer gradient flow information while maintaining its lightweight nature. This information is then used to further process the feature maps passed from the backbone network to extract richer semantic information, thereby improving the model's detection performance.
[0068] S3.1 Input the features after passing through the backbone into the Neck of the network model to further process the feature maps passed from the backbone network in order to extract richer semantic information;
[0069] S3.2 The extracted features are fused from feature maps at different levels using a feature pyramid network. These feature maps have different resolutions, from coarse to fine, corresponding to targets of different scales. The goal of the feature pyramid network is to unify these feature maps to a common resolution for target detection in subsequent stages.
[0070] S3.3 After the feature pyramid is created, the Neck section uses operations such as convolution or upsampling to fuse these features. This helps ensure that features at all scales have similar dimensions so that they can be connected and processed in subsequent layers.
[0071] S3.4. In the Neck part of the model, the C2fGhostv2 network is introduced to replace the last XBL module in the original model before predicting large-scale targets. This allows the model to obtain richer gradient flow information while maintaining its lightweight nature, enabling more efficient feature fusion. Finally, the Neck part outputs shallow feature maps, mid-level feature maps, and deep feature maps, which are used to detect the location and category of the target.
[0072] S4. Using the WIoU loss function balances the training effects of high-quality and low-quality samples, solves the problem of target performance degradation caused by blindly emphasizing high-quality samples, helps the model learn how to generate more accurate bounding boxes, thereby enhancing the robustness and generalization performance of the model.
[0073] S4.1 In the hazardous chemical vehicle target detection model of this invention, a dynamic non-monotonic loss function based on IoU (Wise-IoU) is introduced. Its design goal is to balance the training effect of samples of different quality through a dynamic modulation mechanism. By adopting a method that reduces training intervention on high-quality examples, the penalty for geometric factors can be reduced, making the model rely more on the anchor box itself rather than the features of the target box for prediction. This strategy improves the robustness and generalization performance of the model, enabling it to better adapt to hazardous chemical vehicle targets of different shapes and positions, and improving the model's detection accuracy. The definition of the WIoU loss function is as follows:
[0074] L WIoUv1 =R WIoU L IoU
[0075]
[0076] Among them W g H g The minimum bounding box size is used to prevent R from being... WIoU This generates a gradient that hinders convergence; the superscript * indicates that W... g H g Separate from the computation graph.
[0077] S5. The Head part of the network model receives multi-scale feature maps from the Neck part and generates the location and category information of the target box through convolution and decoding operations. This information is used for the final object detection result, and the final detection result can be obtained through post-processing steps such as NMS.
[0078] S5.1 Input the fused features into the Head part of the network model to perform target detection of hazardous chemical vehicles;
[0079] S5.2. Generate the location and category information of the target boxes through convolution and decoding operations. Output decoding is the process of converting the convolution output into actual target boxes on the image. It involves parsing and scaling the convolution output using anchor box information to obtain the coordinates of the target boxes. This step converts the model's output from coordinates relative to the feature map to coordinates relative to the original image and determines the category and confidence of the target boxes.
[0080] S5.3 After output decoding, Non-Multiple Detection Sequence (NMS) is used to remove highly overlapping redundant target boxes, retaining only the most reliable detection box for each target. The purpose of NMS is to eliminate redundant detection results, ensuring that each target has only one final detection result. Through post-processing steps such as NMS, the final detection result can be obtained.
[0081] S6. Train the hazardous materials vehicle detection network. Input the image processed in step S1 into the hazardous materials vehicle detection network for training. Generate a defect detection model. Save the weights of the trained hazardous materials vehicle detection network to generate a lightweight hazardous materials vehicle detection model for detecting hazardous materials vehicles. This model can be deployed on mobile devices such as drones.
[0082] S6.1 Divide the images processed in step S1 into training set, test set and validation set, and input them into the hazardous chemical vehicle detection network for training.
[0083] S6.2 In the experiments of this invention, we used a computer based on the Windows 10 operating system, equipped with an NVIDIA Tesla V100 SXM2 graphics card with 16GB of video memory. We chose the PyTorch deep learning framework as the development environment, version 1.8.0, and used CUDA 10.2.89 to accelerate the training process. Furthermore, we used Python interpreter version 3.8 and employed the SGD optimizer to adjust the model parameters. Table 1 shows the specific settings of some important experimental parameters.
[0084] Table 1: Experimental Parameter Configuration
[0085]
[0086] S6.3 This invention uses precision (P), average recall (R), average precision (AP), and mean average precision (mAP) as evaluation metrics for the model. We define P as the number of positive samples correctly identified as positive samples, R as the number of negative samples correctly identified as negative samples, AP as the number of negative samples incorrectly identified as positive samples, and mAP as the number of positive samples incorrectly identified as negative samples.
[0087]
[0088]
[0089]
[0090] S6.4. The hazardous chemical vehicle dataset was input into the YOLOv7-tiny model and the improved YOLOv7-tiny model respectively for comparative experiments, and the results are shown in the table below:
[0091]
[0092]
[0093] This invention relates to a chemical safety system, which can be used to detect hazardous chemical vehicles during the transportation of chemical products, thereby completing the detection of hazardous chemical vehicles in chemical transportation equipment.
[0094] The above embodiments are only for illustrating the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly. They should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made in accordance with the spirit and essence of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A method for detecting hazardous chemical vehicles based on an improved YOLOv7-tiny, characterized in that, Includes the following steps: S1. Obtain the image to be processed and preprocess it; First, process the original images in the hazardous chemical vehicle dataset to generate images of uniform size, and then process the images of uniform size a second time. S2. Construct a hazardous chemical vehicle target detection model based on YOLOv7-tiny. In the backbone part of the model, introduce a C2fGhostv2 network and a PConv module. The C2fGhostv2 network is composed of a GhostNetv2 network and a C2f module. The GhostNetv2 network is composed of a Ghost module and a decoupled fully connected attention mechanism (DFC). The GhostNetv2 network replaces multiple repeated residual blocks in the C2f module, achieving lightweight feature extraction and long-range dependency capture. Specifically, C2fGhostv2 is introduced between the first and second max pooling operations in the backbone part to replace the original XBL module there. PConv is used to replace some ordinary convolutions in the last two XBL modules in the backbone to obtain PXBL. The XBL module consists of five standard convolutional modules (CBL). The input features are processed by two parallel CBL modules (first and second). The output features of the first CBL module are then processed by the third and fourth CBL modules. The output features of the first, second, third, and fourth CBL modules are then processed by concat and finally by a fifth CBL module. The third CBL module in the last two XBL modules of the Backbone is replaced by PConv. S3. Introduce a lightweight C2fGhostv2 network into the Neck part of the YOLOv7-tiny target detection model; replace the last XBL module in the original model before predicting large-scale targets with the C2fGhostv2 network to further process the feature maps passed from the backbone network. S3.1 Input the features after passing through the backbone into the Neck of the network model to further process the feature maps passed from the backbone network in order to extract richer semantic information; S3.2 The extracted features are fused from feature maps at different levels using a feature pyramid network; S3.3 After the feature pyramid is created, the Neck section uses convolution or upsampling operations to fuse features; S3.4 The Neck section also introduces the C2fGhostv2 module, replacing the last XBL module in the original model before predicting large-scale targets with the C2fGhostv2 network. Finally, the Neck section outputs shallow feature maps, medium feature maps and deep feature maps respectively, which are used to detect the location and category of the target. S4. Use the WIoU loss function to balance the training effect of the samples; S5. The Head part of the network model receives multi-scale feature maps from the Neck part, and generates the location and category information of the target box through convolution and decoding operations. The image processed in step S1 is input into the hazardous chemical vehicle detection network for training. The weights of the trained hazardous chemical vehicle detection network are saved to generate a lightweight hazardous chemical vehicle detection model for detecting hazardous chemical vehicles.
2. The method for detecting hazardous chemical vehicles based on the improved YOLOv7-tiny according to claim 1, characterized in that, The specific steps of step S1 are as follows: S1.1 Input the images of hazardous chemical vehicles into the model to generate images of uniform size; S1.
2. Mosaic technology is used to enhance the original data. The input hazardous chemical vehicle image is divided into small blocks and recombined to achieve image transformation. Each small block is translated, scaled, cropped, stitched, and its hue, brightness, and saturation are changed. After being stitched together, a new image is generated, thus obtaining the hazardous chemical vehicle dataset.
3. The method for detecting hazardous chemical vehicles based on the improved YOLOv7-tiny according to claim 1, characterized in that, The specific steps of step S2 are as follows: S2.1 Input the preprocessed image into the Backbone part of the network model; S2.2 The input image undergoes a series of convolutional layers and pooling layers to extract local features from the input image. S2.
3. C2fGhostv2 is introduced between the first and second max pooling operations in the backbone part of the model, replacing the XBL module there. For input features X∈R H×W×C_in First, the data stream enters the first 1×1 convolution of the C2fGhostv2 module, and then enters two branches: the main branch C1 and the secondary branch W1. The main branch C1 first performs a split operation to divide the data stream into two branches C2 and W2. C2 is used as input to enter the GhostNetv2 network, which is then fed into the Ghost module and the decoupled fully connected attention mechanism DFC. The Ghost module generates output feature C3, and the decoupled fully connected attention mechanism DFC generates attention matrix M. The Sigmoid function is used to restrict the output of the attention matrix to the range [0,1]. The dot product of the two branches is then used to obtain output feature C4. C4 is processed by the Ghost module to generate feature C5. Then, the output C5 is concatenated with C2 to obtain the total output feature Y1 of the GhostNetv2 part; Y1∈R H×W×0.5C_in The various branches, namely the outputs Y1 and W1-Wn, are concatted to obtain C_out. Finally, a 1×1 convolution is performed to reduce the dimensionality of the features to their original size, resulting in the final output Y2∈R. H×W×C_out ; S2.4 After step S2.3, the features of the image are extracted and enhanced. Next, the PConv module is introduced into the backbone part of the model to replace the partial ordinary convolution of the last two XBL modules in the backbone part, so that the model can make more effective use of the information in the feature map. S2.5 Finally, a series of feature maps are output, each corresponding to an image region of a different scale.
4. The method for detecting hazardous chemical vehicles based on the improved YOLOv7-tiny according to claim 1, characterized in that, The WIoU loss function in step S4 is specifically as follows: S4.1 The definition of the WIoU loss function is as follows: L WIoUv1 =R WIoU L IoU (5) Among them W g H g The minimum bounding box size is used to prevent R from being... WIoU This generates a gradient that hinders convergence; the superscript * indicates that W... g H g Separate from the computation graph.
5. The method for detecting hazardous chemical vehicles based on the improved YOLOv7-tiny according to claim 1, characterized in that, The specific steps of step S5 are as follows: S5.1 Input the fused features into the Head part of the network model to perform target detection of hazardous chemical vehicles; S5.
2. The position and category information of the target box are generated through convolution and decoding operations. Output decoding is the process of converting the convolution output into the actual target box on the image. The anchor box information is used to parse and scale the convolution output to obtain the coordinates of the target box. S5.3 After output decoding, use NMS to remove highly overlapping redundant target boxes, retain only the most reliable detection box for each target, and obtain the final detection result.
Citation Information
Patent Citations
Lightweight target detection method
CN114120019A
Real-time small target detection method and device based on sliding window, equipment and medium
CN116740416A