Gunpowder filling scattering detection method based on improved YOLOv5s
By improving the YOLOv5s network, the problems of low efficiency, poor accuracy and high resource demand in gunpowder loading and spillage detection have been solved, real-time and accurate identification of tiny particles and adaptation to complex environments have been achieved, and an efficient automated detection solution has been provided.
Patent Information
- Application Number
- CN202410472438.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-19
- Publication Date
- 2024-08-23
AI Technical Summary
Existing gunpowder filling spill detection technology has problems such as low efficiency, limited accuracy, high labor costs, poor adaptability to complex environments, difficult particle identification problems, and high real-time and computing resource requirements.
The improved YOLOv5s network is adopted, by replacing standard convolutions with depth-separable convolutions, introducing a coordinate attention mechanism, and modifying the loss function to VariFocal Loss to improve detection speed and accuracy, adapt to complex environments and reduce computing resource requirements.
It achieves real-time, high-speed and accurate gunpowder filling and spillage detection, improves the ability to identify tiny particles, reduces the false alarm rate, enhances the robustness and generalization capabilities of the model, simplifies hardware deployment, and provides more reliable automation Testing plan.
Smart Images

Figure CN118537528A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of deep learning target detection, and is applied to a process of detecting the spilling of gunpowder charging, and is specifically a method for detecting the spilling of gunpowder charging based on improved YOLOv5s. Background Art
[0002] In the industrial production process involving gunpowder filling, accurate identification and timely disposal of gunpowder filling spillage scenes are of vital importance to ensuring production safety, maintaining product quality and optimizing resource utilization. For such scenes, existing detection solutions mainly include traditional manual detection and emerging automated detection based on computer vision technology, but each has technical challenges and limitations.
[0003] Traditionally, the detection of gunpowder spillage during gunpowder loading mainly relies on manual inspection and visual inspection. Operators inspect the work area regularly or irregularly, and use their experience to identify signs of gunpowder particle spillage, such as color, shape, and distribution characteristics. Once an abnormality is found, cleanup measures are taken immediately and the incident is recorded. The advantage of this type of solution is its intuitiveness and flexibility, which is suitable for complex and non-standardized production environments.
[0004] However, manual inspection has the following significant technical problems when facing the scene of gunpowder spillage:
[0005] 1. Inefficiency: The manual inspection cycle is long, and it is impossible to achieve continuous and real-time monitoring of the gunpowder filling process, which may lead to delayed discovery of spillage incidents and increase potential risks.
[0006] 2. Limited accuracy: Human eye recognition is affected by factors such as light, angle, and fatigue level. It has limited ability to recognize tiny, scattered gunpowder particles or those that are similar in color to the background, and is prone to missed detections.
[0007] 3. High labor costs: Long-term reliance on a large number of manual inspections not only increases labor costs, but also poses a potential threat to the personal safety of operators in a high-risk environment.
[0008] With the development of computer vision and deep learning technologies, new gunpowder spill detection systems are gradually being applied to gunpowder loading scenarios. Such systems usually capture real-time images through cameras installed on the production line and use pre-trained deep learning models to analyze the images to identify whether there is gunpowder particle spillage. Although this automated detection solution significantly improves the detection efficiency and accuracy of gunpowder spill scenarios, it still faces the following technical challenges:
[0009] 1. Adaptability to complex environments: The gunpowder loading site may have adverse conditions such as lighting changes, dust interference, and complex backgrounds, requiring the detection system to have strong environmental adaptability and anti-interference capabilities.
[0010] 2. Identification of tiny particles: Some gunpowder particles may be extremely small and have different scattering shapes. The deep learning model needs to accurately distinguish gunpowder particles from similar background elements to avoid false positives and negatives.
[0011] 3. Real-time and computing resource requirements: Real-time image processing and deep learning reasoning require high hardware computing power, and it is necessary to reduce system resource consumption while ensuring detection speed.
[0012] Regardless of whether it is traditional detection or automated detection, these challenges of existing solutions constitute the key issues that need to be urgently addressed in the current gunpowder loading spill detection task, providing broad development space for the research and development and improvement of innovative detection technologies. Summary of the invention
[0013] Based on the current status of the background technology, in order to solve the problems of insufficient detection accuracy, insufficient generalization ability and over-reliance on manual inspection in the current solution, the present invention proposes a gunpowder filling spill detection method based on improved YOLOv5s. The present invention uses the YOLOv5s network to make scene-specific improvements, which significantly improves the detection speed and accuracy of the spilling situation during the gunpowder filling process, thereby achieving an automated and precise detection effect, providing a more reliable and sustainable solution for industrial production, and has a high application value.
[0014] The present invention adopts the following technical solutions to achieve the purpose:
[0015] A method for detecting gunpowder filling spillage based on improved YOLOv5s, the method comprising the following steps:
[0016] S1. Obtain the YOLOv5s network as the basis for improving the gunpowder filling spill detection model;
[0017] S2, replace all standard convolutions in the baseline configuration of the YOLOv5s network with depthwise separable convolutions;
[0018] S3. Introduce the coordinate attention mechanism for the last layer of the backbone network in the YOLOv5s network;
[0019] S4. Change the CIoU Loss loss function in the YOLOv5s network to the VariFocal Loss loss function, complete the improvement and perform network training;
[0020] S5. After completing network training and verification, a gunpowder filling spill detection model is obtained and applied to the gunpowder filling spill detection task on the actual production line.
[0021] Specifically, in step S2, the baseline configuration of the YOLOv5s network includes a backbone network baseline and a neck network baseline. All 3×3 standard convolutions in the backbone network baseline and the neck network baseline are replaced with 3×3 depthwise separable convolutions; the convolution operation of the depthwise separable convolution includes a depthwise convolution stage and a pointwise convolution stage.
[0022] Specifically, in step S3, the introduction process of the coordinate attention mechanism is as follows: according to the code description of the coordinate attention mechanism, write the code of the coordinate attention module or reuse the existing code, make the input dimension of the coordinate attention module the same as the input dimension of the last layer feature map of the backbone network, and generate an output of the same dimension.
[0023] Specifically, in step S4, the calculation formula of the modified VariFocal Loss loss function is L variocal as follows:
[0024] L variocal (p t )=-(1-p t ) γ ·log(p t )
[0025] In the formula, p t is the probability predicted by the network, which represents the network's confidence in the target; γ is the zoom factor used to adjust the weights of difficult and easy samples; the larger the value of γ, the more the network pays attention to samples that are difficult to classify.
[0026] Specifically, in step S4, the gunpowder spill dataset is used to train, verify and test the improved YOLOv5s network; the gunpowder spill dataset is obtained by: collecting original data and performing data preprocessing, annotating and saving the gunpowder powder area in the preprocessed data; performing data enhancement processing on the original data and the annotated and saved data, and then saving them as the gunpowder spill dataset in a preset format.
[0027] Specifically, in step S5, the performance of the improved YOLOv5s network is verified by the validation set in the data set, and after the gunpowder filling spill detection model is obtained, it is tested using the test set in the data set to evaluate the model's prediction ability and positioning accuracy in the gunpowder filling spill detection task; during the test, the model is made to infer and predict each image in the test set to obtain a prediction result of the presence of gunpowder powder, and the prediction result is a rectangular bounding box including a category label and a position coordinate; the prediction result is compared with the true annotation to evaluate the performance of the model.
[0028] In summary, due to the adoption of this technical solution, the improvement of the YOLOv5s network made by the present invention brings the following beneficial effects in scene applications:
[0029] First, the improved YOLOv5s network can achieve real-time and high-speed detection. Thanks to the efficient architecture design of the YOLOv5s network, the detection model significantly shortens the inference time while maintaining high detection accuracy, enabling the system to instantly capture and identify the subtle spilling behavior of gunpowder particles, effectively preventing the occurrence of safety accidents. The model obtained by the present invention has a simple structure, moderate computational complexity, and is easy to deploy on various hardware platforms, thereby reducing the hardware threshold in practical applications and becoming a specific intelligent solution for gunpowder loading production lines.
[0030] Secondly, in response to the problem of tiny particles that may fall during the gunpowder filling process, the specific effects of the improvement of the YOLOv5s network are as follows:
[0031] 1. Introducing depthwise separable convolution to replace traditional convolution operations, by decomposing the convolution operation into two steps: depthwise convolution and pointwise convolution, the computational complexity of the model is significantly reduced, and the ability to extract small target features is enhanced. This improvement enables the model to accurately capture tiny gunpowder particles while maintaining a high-resolution feature map, effectively solving the problem of small target recognition and improving detection accuracy.
[0032] 2. Add a coordinate attention mechanism to the YOLOv5s network to further improve the model's sensitivity to the location of gunpowder particles and positioning accuracy by adaptively enhancing the channel information related to the target position in the feature map. This mechanism helps the model accurately distinguish gunpowder particles from similar background elements in complex backgrounds, reduces the false alarm rate, and improves the robustness and generalization ability of detection.
[0033] 3. In view of the large change in target scale and high proportion of small targets in the gunpowder loading scene, the present invention uses the VariFocal Loss loss function as the training loss function. VariFocal Loss dynamically adjusts the weights of positive and negative samples, focuses on small targets that are difficult to classify, and strengthens the model's recognition training for small gunpowder particles, thereby significantly improving the model's detection balance and overall accuracy for gunpowder particles of different sizes. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 The overall process diagram of the method of the present invention is briefly described;
[0035] Figure 2 A schematic diagram of the hierarchical structure relationship of the improved YOLOv5s network of the present invention;
[0036] Figure 3 Schematic diagram of the coordinate attention module introduced in the present invention. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.
[0038] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. 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.
[0039] Example
[0040] A gunpowder filling spill detection method based on improved YOLOv5s, Figure 1 The process flow of the method is shown, wherein each step can be summarized as follows:
[0041] S1. Obtain the YOLOv5s network as the basis for improving the gunpowder filling spill detection model;
[0042] S2, replace all standard convolutions in the baseline configuration of the YOLOv5s network with depthwise separable convolutions;
[0043] S3. Introduce the coordinate attention mechanism for the last layer of the backbone network in the YOLOv5s network;
[0044] S4. Change the CIoU Loss loss function in the YOLOv5s network to the VariFocal Loss loss function, complete the improvement and perform network training;
[0045] S5. After completing network training and verification, a gunpowder filling spill detection model is obtained and applied to the gunpowder filling spill detection task on the actual production line.
[0046] This embodiment will introduce the details of each step in detail according to the above step sequence.
[0047] First, this embodiment uses the YOLOv5s network to perform the gunpowder filling spill detection task; the YOLOv5s network is a smaller variant of the YOLOv5 series, which is lightweight and designed as a small network with relatively low network size, computational complexity, and memory usage, making it suitable for deployment in resource-constrained environments or applications with high real-time requirements. Despite its small size, the network can still maintain good detection accuracy.
[0048] In step S1, in order to obtain the YOLOv5s network, as a preferred method, you can visit the official GitHub repository of YOLOv5, find the different versions that have been released and the corresponding pre-trained weight files on the release page, and after downloading, verifying and configuring the pre-trained weight files, you can use this network as the basis for improving the gunpowder filling spill detection model. There is no unique way to obtain the YOLOv5s network, and it can be obtained from other unofficial channels according to actual conditions.
[0049] In step S2, this embodiment uses the YOLOv5s network to focus on the core components of the network, namely the backbone network and the neck network. At this time, a key optimization improvement strategy is selected, that is, for the backbone network baseline and the neck network baseline, all 3×3 standard convolutions are replaced with 3×3 depth-separable convolutions. The baseline is the basic structure and related configuration parameters of the pre-trained network obtained in step S1, and the baselines of each component of the network are the starting point for its improvement.
[0050] In the backbone network, the original standard convolution structure is replaced by a depthwise separable convolution structure, which divides the convolution operation into two stages: depthwise convolution and pointwise convolution, thereby effectively reducing the number of network parameters. Similarly, in the neck network, a depthwise separable convolution structure is used to replace the original standard convolution structure to maintain the consistency and efficiency of the overall network. Through this optimization and improvement strategy for the backbone network and the neck network, the scale of network parameters is successfully reduced, while maintaining the network's efficient performance, providing an excellent foundation for subsequent gunpowder filling spill detection tasks.
[0051] The preferred replacement process given in this embodiment is: first open the source code file of the YOLOv5s network, and find all standard convolutional layers defined by the target baseline in the network architecture; the standard convolutional layer is expressed as a Conv or C module; for the standard convolutional layer that has been found, delete it or annotate it; then use the depthwise separable convolution library to create a deep convolutional layer with the same baseline parameters as the original standard convolutional layer, and ensure that the number of input and output channels is also the same as the original standard convolutional layer; then create a 1×1 point-by-point convolutional layer, keep the original attribute parameters and attachments unchanged, connect the input of the original standard convolutional layer to the newly created deep convolutional layer, connect the output of the deep convolutional layer to the point-by-point convolutional layer, and then use the output of the point-by-point convolutional layer as the output position of the original standard convolutional layer to ensure that the connection relationship between the front and back layers of the network remains consistent, and finally recompile and run the YOLOv5s network to verify the replacement process.
[0052] In step S3, this embodiment uses the YOLOv5s network and focuses on the backbone network therein, and introduces a coordinate attention mechanism in its last layer. The corresponding coordinate attention module can be found in Figure 3 The introduction of this mechanism aims to further optimize the network's feature extraction capability, reduce the interference of background information on target detection, make the network more focused on the precise location of the target, and improve the network's generalization ability.
[0053] In this embodiment, the introduction process of the coordinate attention mechanism is specifically as follows: based on the code description of the coordinate attention mechanism, the code of the coordinate attention module is written or the existing code is reused, so that the input dimension of the coordinate attention module is the same as the input dimension of the last layer feature map of the backbone network, and an output of the same dimension is generated.
[0054] In the coordinate attention module, an additional coordinate channel is added to the original feature map. The coordinate channel has the absolute or relative coordinate information of each pixel. At the same time, convolution and / or self-attention operations are used to fuse the original features and coordinate information to generate an attention feature map with position sensitivity. The compatibility of the attention feature map with the original feature map is ensured through scaling and normalization operations. The output of the last layer of the backbone network in the YOLOv5s network is directly inserted into the coordinate attention module. The YOLOv5s network is recompiled and run to verify the introduction of the coordinate attention mechanism.
[0055] In step S4, the calculation formula of the VariFocal Loss loss function modified in this embodiment is L variocal as follows:
[0056] L variocal (p t )=-(1-p t ) γ ·log(p t )
[0057] In the formula, p t is the probability predicted by the network, which represents the network's confidence in the target; γ is the focusing factor used to adjust the weights of difficult and easy samples; the larger the value of γ, the more the network focuses on samples that are difficult to classify.
[0058] Since the spilled gunpowder powder is a small target and the image background is large, the background class is usually an easy-to-classify sample, while the powder class is a difficult-to-classify sample. Therefore, this embodiment uses the VariFocal Loss loss function to solve the problem of imbalance between positive and negative samples, which can effectively improve the detection accuracy of gunpowder powder.
[0059] In this embodiment, the modification process of this loss function is specifically as follows: locate the code call location of CIoU Loss, which usually involves a function named loss or compute_loss, in which the relevant implementation of CIoU Loss is explicitly called, so it is removed by deletion or annotation. Then, according to the formula definition of VariFocal Loss, write a new implementation code; the implementation code of VariFocal Loss includes the calculation of classification loss (focal loss) and regression loss (related to IoU), as well as adjustable hyperparameters (such as the aforementioned zoom factor γ). If an open source VariFocal Loss implementation library or function has been obtained here, it can be directly imported and called. Finally, the new VariFocal Loss loss function receives the output of the network (such as predicted bounding box, category probability, etc.) and returns the total loss value, performs unit testing, verifies the calculation logic, and completes the modification of the loss function.
[0060] After the loss function is modified, the targeted improvement of the YOLOv5s network is completed, which can be seen in Figure 2 The improved hierarchical structure relationship is shown. Regarding the application of the improved YOLOv5s network in the gunpowder filling spill detection process, this embodiment is preferably introduced as follows, involving the training, verification and testing of the network.
[0061] In step S4, this embodiment uses the gunpowder spill dataset to train, verify and test the improved YOLOv5s network. The gunpowder spill dataset is obtained by collecting gunpowder spill images and scaling the images to a fixed size of 640×640 pixels to ensure that the input images have a consistent size. Use LabelImg annotation software to adapt to the label format of YOLO, accurately annotate the gunpowder powder area on each image, and save the annotation results as corresponding txt format files.
[0062] In order to enhance the diversity and robustness of the image data in the dataset, this embodiment performs a series of data enhancement processing on the original gunpowder spill images and the corresponding annotated txt format files, including rotation, translation, scaling, noise and brightness adjustment operations, to simulate different perspectives and conditions in the real environment, enrich the final dataset, and improve the generalization ability of the model.
[0063] Finally, the data is divided into a training set, a validation set, and a test set according to the format standard of the COCO dataset, and integrated and saved as a gunpowder spill dataset. In this embodiment, the division ratio of the training set, the validation set, and the test set is 7:2:1 to ensure sufficient coverage of training, validation, and testing. In addition, in order to improve the efficiency of model training, the image data is also normalized, and the range of pixel values is normalized from the original [0,255] to [0,1], thereby reducing the numerical range of the input data, which helps to accelerate the convergence and training speed of the model.
[0064] In step S5, the performance of the improved YOLOv5s network is verified through the validation set, and after the gunpowder filling spill detection model is obtained, it is tested using the test set to evaluate the model's prediction ability and positioning accuracy in the gunpowder filling spill detection task.
[0065] During the test, the model is made to make inference predictions for each image in the test set, and the prediction result of the presence of gunpowder powder is obtained. The prediction result is a rectangular bounding box including the category label and the position coordinates, where the position coordinates may include the coordinates of the upper left corner and the lower right corner of the rectangular bounding box. The prediction result is compared with the real annotation to evaluate the performance of the model.
[0066] Finally, after the verification and testing process, the gunpowder charging spill detection model that meets the performance requirements can be applied to the actual production line and used for a long time as a reliable and sustainable solution for the gunpowder charging spill detection task.
Claims
1. A gunpowder filling spill detection method based on improved YOLOv5s, It is characterized in that The method comprises the following steps: S1. Obtain the YOLOv5s network as the basis for improving the gunpowder filling spill detection model; S2, replace all standard convolutions in the baseline configuration of the YOLOv5s network with depthwise separable convolutions; S3. Introduce the coordinate attention mechanism for the last layer of the backbone network in the YOLOv5s network; S4. Change the CIoU Loss loss function in the YOLOv5s network to the VariFocal Loss loss function, complete the improvement and perform network training; S5. After completing network training and verification, a gunpowder filling spill detection model is obtained and applied to the gunpowder filling spill detection task on the actual production line.
2. According to claim 1, a method for detecting gunpowder filling and spilling based on improved YOLOv5s, Features: In step S2, the baseline configuration of the YOLOv5s network includes a backbone network baseline and a neck network baseline.
3. A method for detecting gunpowder filling and spilling based on improved YOLOv5s according to claim 2, Features: All 3×3 standard convolutions in the backbone network baseline and the neck network baseline are replaced by 3×3 depthwise separable convolutions; the convolution operation of the depthwise separable convolution includes a depthwise convolution stage and a pointwise convolution stage.
4. A method for detecting gunpowder filling and spilling based on improved YOLOv5s according to claim 3, Features: During the replacement process, first open the source code file of the YOLOv5s network and find all the standard convolutional layers defined by the target baseline in the network architecture; the standard convolutional layer is expressed as a Conv or C module; for the standard convolutional layers that have been found, delete or annotate them; then use the depthwise separable convolutional library to create a deep convolutional layer with the same baseline parameters as the original standard convolutional layer, and ensure that the number of input and output channels is also the same as the original standard convolutional layer; then create a 1×1 point-by-point convolutional layer, keep the original attribute parameters and attachments unchanged, connect the input of the original standard convolutional layer to the newly created deep convolutional layer, connect the output of the deep convolutional layer to the point-by-point convolutional layer, and then use the output of the point-by-point convolutional layer as the output position of the original standard convolutional layer to ensure that the connection relationship between the front and back layers of the network remains consistent, and finally recompile and run the YOLOv5s network to verify the replacement process.
5. A method for detecting gunpowder filling and spilling based on improved YOLOv5s according to claim 1, Features: In step S3, the introduction process of the coordinate attention mechanism is specifically as follows: according to the code description of the coordinate attention mechanism, the code of the coordinate attention module is written or the existing code is reused, so that the input dimension of the coordinate attention module is the same as the input dimension of the last layer feature map of the backbone network, and the output of the same dimension is generated; In the coordinate attention module, an additional coordinate channel is added to the original feature map. The coordinate channel has the absolute or relative coordinate information of each pixel. At the same time, convolution and / or self-attention operations are used to fuse the original features and coordinate information to generate an attention feature map with position sensitivity. The compatibility of the attention feature map with the original feature map is ensured through scaling and normalization operations. The output of the last layer of the backbone network in the YOLOv5s network is directly inserted into the coordinate attention module. The YOLOv5s network is recompiled and run to verify the introduction of the coordinate attention mechanism.
6. A method for detecting gunpowder filling and spilling based on improved YOLOv5s according to claim 1, Features: In step S4, the modification process of the loss function is specifically as follows: locate the code call location of CIoU Loss and remove it by deletion or commenting; write a new implementation code according to the formula definition of VariFocal Loss; the implementation code of VariFocal Loss includes the calculation of the classification loss part and the regression loss part, as well as adjustable hyperparameters; finally, let the new VariFocal Loss loss function receive the output of the network and return the total loss value, perform unit testing, verify the calculation logic, and complete the modification of the loss function.
7. A method for detecting gunpowder spillage based on improved YOLOv5s according to claim 6, Features: The calculation formula of the modified VariFocal Loss loss function is L variocal as follows: L variocal (p t )=-(1-p t ) γ ·log(p t ) In the formula, p t is the probability predicted by the network, which represents the network's confidence in the target; γ is the zoom factor used to adjust the weights of difficult and easy samples; the larger the value of γ, the more the network pays attention to samples that are difficult to classify.
8. A method for detecting gunpowder spillage based on improved YOLOv5s according to claim 1, Features: In step S4, the improved YOLOv5s network is trained using the gunpowder spill dataset; the gunpowder spill dataset is obtained by: collecting original data and performing data preprocessing, annotating and saving the gunpowder powder area in the preprocessed data; performing data enhancement processing on the original data and the annotated and saved data, and then saving them as the gunpowder spill dataset in a preset format.
9. A method for detecting gunpowder spillage based on improved YOLOv5s according to claim 8, Features: The collected raw data is the gunpowder spill image. First, the image is uniformly scaled to a preset size, and then the gunpowder powder area in the image is annotated using annotation software. The YOLO label format is used in the annotation process, and the image is saved after the annotation is completed. The original gunpowder spill image and the annotated and saved image are subjected to data enhancement processing by matching rotation, translation, scaling, noise and brightness adjustment; Finally, according to the format of the COCO dataset, the data is divided into training set, validation set and test set, and integrated and saved as the gunpowder spill dataset.
10. A method for detecting gunpowder spillage based on improved YOLOv5s according to claim 9, Features: In step S5, the performance of the improved YOLOv5s network is verified by the validation set, and after the gunpowder filling spill detection model is obtained, it is tested using the test set to evaluate the model's prediction ability and positioning accuracy in the gunpowder filling spill detection task; during the test, the model is made to infer and predict each image in the test set to obtain a prediction result of the presence of gunpowder powder, and the prediction result is a rectangular bounding box including a category label and position coordinates; the prediction result is compared with the true annotation to evaluate the performance of the model.
Citation Information
Patent Citations
Deep learning-based airtight container airtightness water detection method
CN115760771A
Fire detection method and system
CN117809247A
General target detection method for adaptive attention guidance mechanism
WO2021139069A1
