Sub-cartridge case surface defect detection method and image training and reasoning integrated platform
By improving the YOLOv5 model structure and building an integrated platform, the problems of low efficiency and low accuracy in bullet casing surface defect detection have been solved, achieving efficient and stable automated detection and model deployment, adapting to complex backgrounds and small target defects.
Patent Information
- Application Number
- CN202511464130.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-14
- Publication Date
- 2026-01-09
AI Technical Summary
In existing technologies, the detection efficiency and accuracy of bullet casing surface defects are low. Manual inspection is easily affected by subjective factors. Traditional machine vision and deep learning algorithms have difficulty effectively identifying small target defects in complex backgrounds. The lack of an end-to-end industrial-grade inspection platform makes model deployment difficult.
We adopted a data augmentation strategy of Mosaic splicing and CopyPaste pasting to improve the YOLOv5 model structure. We introduced the CBAM mechanism and Focal Loss and AR-CIoU loss function to build an integrated platform for data acquisition, annotation, training and deployment. We dynamically adjusted the Anchor box configuration to improve the model's robustness and detection accuracy for small defect targets.
It significantly improves the model's robustness to small defects and complex backgrounds, enhances detection accuracy, and enables closed-loop management from model construction to field application, ensuring the system's stability and adaptability.
Smart Images

Figure CN121304597A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of image recognition and deep learning technology, and in particular to a method for detecting surface defects in bullet casings and an integrated platform for image training and inference. Background Technology
[0002] Bullet casings are an indispensable basic component of ammunition systems, and their geometric accuracy and surface quality directly affect the ammunition's assembly performance, safety, and firing accuracy. In high-speed automated production lines, the mass production of bullet casings places high demands on the efficiency, precision, and stability of surface quality inspection. Minor anomalies such as scratches, cracks, indentations, dirt, corrosion spots, plating fading, and foreign matter adhesion, if not detected in time, can lead to serious consequences such as loading failure, jamming, and barrel explosion.
[0003] Currently, the quality inspection of surface defects in bullet casings still relies primarily on manual visual inspection, with quality inspectors visually identifying and judging defects at fixed workstations. This method is not only inefficient but also highly susceptible to subjective judgment, easily leading to false positives and false negatives, especially under continuous long-term operation, where the detection rate fluctuates significantly. Furthermore, manual inspection is difficult to digitally record and trace, resulting in inconsistent inspection results and failing to meet the basic requirement of "full-process digital control" in modern military quality control systems.
[0004] Although traditional machine vision technology has been gradually introduced into bullet casing inspection in recent years, attempting to identify defect areas through image processing algorithms, it is often unstable in practical applications due to interference factors such as strong reflections on metal surfaces, uneven highlights, complex textures, and changes in lighting angles. Especially for small defects with low contrast, such as minute scratches and pinhole dents, traditional algorithms struggle to extract effective features, resulting in low accuracy, poor generalization ability, and difficulty in handling complex scenes and various types of defects.
[0005] Deep learning technology, especially YOLO-based target detection networks, has demonstrated excellent real-time performance and detection capabilities in industrial quality inspection. YOLOv5, as a widely used lightweight detection model, already exhibits good performance in general target detection tasks. However, YOLOv5 still suffers from reduced detection accuracy and a high false negative rate when dealing with small targets, densely distributed defects, and images against bright backgrounds, making it difficult to directly apply to bullet casing detection scenarios.
[0006] Furthermore, most current deep learning detection systems focus only on the model training stage and lack end-to-end industrial-grade image detection platform support. This results in low data annotation efficiency, complex model deployment, and difficulty in version iteration, causing a disconnect in the model's process from training to deployment, which severely restricts the industrial deployment and large-scale promotion of the model.
[0007] Therefore, there is an urgent need to propose a detection platform that integrates an improved YOLOv5 model structure, adapts to the needs of identifying small defects in bullet casings, and has the capabilities of data management, image annotation, model training, and inference deployment. This platform would improve detection accuracy, enhance system stability, and enable intelligent and automated deployment in the industrial sector, thereby addressing the technical bottlenecks of low efficiency, poor algorithm robustness, and insufficient platform capabilities in existing manual detection methods. Summary of the Invention
[0008] To address the shortcomings of existing technologies, this invention provides a method for detecting surface defects in bullet casings and an integrated platform for image training and inference. It overcomes the limitations of traditional manual visual inspection, which is inefficient and subject to subjective influence. It solves the problem that traditional machine learning algorithms are unable to cope with complex scenes and multiple types of defects in practical applications. It improves the detection accuracy of YOLOv5 when dealing with images of small targets, densely distributed defects, and images against a high-brightness background. Furthermore, it overcomes the constraints on the industrial deployment and large-scale promotion of models caused by the lack of end-to-end industrial-grade detection platform support.
[0009] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a method for detecting defects on the surface of a bullet casing, comprising the following steps: S1. Acquire the original 360-degree images of the bullet casing, unfold and reconstruct them into a complete planar image, and perform preprocessing such as brightness normalization, contrast stretching, and edge enhancement. S2. A data augmentation strategy combining Mosaic stitching and CopyPaste is used to amplify samples in the preprocessed images to obtain enhanced training samples, thereby improving the model's robustness in recognizing small defect targets in complex backgrounds. S3. Extract the features of the defect target on the bullet casing surface, the features including aspect ratio and area; perform logarithmic transformation and standardization on its area, and perform anchor re-clustering on the extracted features, increase the number of small-sized anchor boxes and adjust the aspect ratio and density of the anchor boxes, and dynamically update the size and number of anchor boxes according to the resolution of the feature map and the complexity of the defect target. S4. Construct a defect detection model based on the YOLOv5 architecture, add a shallow detection head to the defect detection model and introduce the CBAM mechanism; S5. Replace the original classification loss function and bounding box regression loss function of the YOLOv5 structure in the defect detection model with Focal Loss and AR-CIoU loss to improve the imbalance of positive and negative samples for small defect targets and improve the accuracy of bounding box regression.
[0010] Furthermore, in step S1, the specific process includes the following steps: S11. Use a high-resolution industrial camera to capture 360-degree surround images of the bullet casing to obtain its original images. Then, based on the central axis, unfold and reconstruct the original images to generate a complete planar image of the bullet casing surface, which serves as the original image. S12. Perform brightness normalization processing on the original image to make its gray level concentrated in the interval [−1,1]. S13. Perform contrast stretching and edge enhancement on the image after brightness normalization to highlight the visibility of small defect targets.
[0011] Furthermore, in step S2, the specific process includes the following steps: S21. Given a preprocessed image, use Mosaic stitching to perform data augmentation on it, generating a new stitched image to simulate the defect behavior under different backgrounds; S22. Use CopyPaste to process the preprocessed image, paste the defective target area from one image to a random position in another image, and generate a new image after pasting. S23. Merge the stitched new image and the pasted new image to generate enhanced training samples.
[0012] Furthermore, in step S3, the specific process includes the following steps: S31. Analyze and statistically analyze the width and height of the defect targets on the bullet casing surface, and extract the aspect ratio and area of the defect targets; S32. Perform logarithmic transformation and standardization on the area to make the eigenvalues more evenly distributed and located on the same scale. S33. Based on the K-Means++ clustering algorithm, the extracted features are re-clustered using Anchors to optimize the size of the Anchor boxes; S34. Increase the number of small-sized anchor boxes to improve the detection accuracy of small defect targets; S35. Adjust the aspect ratio of the Anchor box to accommodate the irregular shape of the defective target; S36. Assign more anchor boxes to high-density areas of defective targets to ensure that defective targets are detected accurately. S37. During model training, the Anchor box configuration is dynamically updated. Smaller Anchor boxes are used for higher resolution feature maps, and larger Anchor boxes are used for lower resolution feature maps. The number of Anchor boxes is also dynamically adjusted according to the complexity of the defect target to adapt to different shapes of the defect target.
[0013] Furthermore, in step S31, special attention is paid to the features of small defect targets so that the Anchor box can fit the small defect targets.
[0014] Furthermore, in step S4, the specific process includes the following steps: S41. Add a shallow detection head to the P2 layer of the YOLOv5 structure to specifically handle small-scale defect targets; S42. Introduce the CBAM mechanism into the backbone feature extraction module of the YOLOv5 architecture to enhance the model's ability to extract features from defect target regions.
[0015] Furthermore, in step S5, the specific process includes the following steps: S51. Replace the classification loss function in the original YOLOv5 structure with Focal Loss, the expression of which is: ; In the formula, Indicates Focal Loss; For defect category weighting coefficients, Indicates the defect category; Adjustment factor for easy and difficult samples; This refers to the probability of the defect category predicted by the defect detection model. When the sample is easy to classify, Larger Approaching zero reduces the loss weight of that sample; Represents logarithmic calculation; S52. Design the AR-CIoU loss as the bounding box regression loss function, and introduce the bounding box aspect ratio consistency constraint term into the CIoU loss function used in the original YOLOv5 structure. The expression is as follows: ; ; In the formula, This represents the designed AR-CIoU loss; Indicates intersection, union, and ratio; This indicates the difference in aspect ratio between the detection bounding box and the ground truth bounding box; This is a weighting factor; by adjusting this factor, the IoU and The importance of consistency; Represents the arctan operation; The distance between the center point of the detection box and the center point of the ground truth box; The diagonal length of the smallest closure region that can simultaneously contain both detection boxes and ground truth boxes; This represents the weighting coefficient used to balance the IoU loss and the aspect ratio consistency loss; This parameter represents the aspect ratio of the detection box and the ground truth box, and is used to measure the consistency of the aspect ratio. This is an angle parameter used to describe the angular relationship between the detection box and the ground truth box; The coordinates of the center point of the detection frame; The coordinates of the center point of the true bounding box; , These are the height and width of the detection frame, respectively; , These represent the height and width of the actual bounding box, respectively.
[0016] Furthermore, the present invention also provides an integrated training and inference platform for bullet casing surface defect images, for applying the bullet casing surface defect detection method described above, including: a project management module, a dataset management module, a sample amplification module, a training configuration interface, a model training module, a training task monitoring interface, a model evaluation module, and a deployment management module. The project management module allows you to create or open an existing defect detection project and select an initial defect detection model and the corresponding dataset version as the training basis. The dataset management module expands, reconstructs, and preprocesses the newly acquired original images of bullet casings, uploads them as additional images, and labels them with defect categories, so that they can participate in subsequent iterative training as new samples. Before iterative training, the module automatically performs dataset checks, performs integrity checks, sample counts, and label consistency checks on the training set, validation set, and test set after adding new samples. The sample augmentation module applies a data augmentation strategy that combines Mosaic splicing and CopyPaste pasting to the training set, validation set, and test set after adding new samples, for subsequent training of the defect detection model. The training configuration interface allows users to select between full training mode and incremental training mode. In incremental training mode, the platform fine-tunes the weights based on the parameters of the original defect detection model, retains the existing feature learning results, and incorporates the feature information of newly added samples. At the same time, this interface allows users to adjust the number of training rounds, learning rate, optimizer type, data augmentation strategy, and loss function configuration. The model training module is used to perform Anchor re-clustering, adjust the number of small-sized Anchor boxes, and adjust the aspect ratio, density, size, and number of Anchor boxes. At the same time, the module has built-in training clusters or cloud computing resources, and iteratively trains the defect detection model based on Focal Loss and AR-CIoU loss. It supports multi-GPU parallelism and breakpoint resume training, and records various training indicators in real time during the training process. The training task monitoring interface dynamically displays various training indicators recorded in real time during the training process. The model evaluation module generates an updated model evaluation report after the defect detection model has been iteratively trained. It compares the performance changes of the old and new defect detection models on the test set and new samples, and binds and archives the trained model file, training configuration, dataset version and evaluation results to ensure that the iteration process is traceable. The deployment management module pushes the trained defect detection model to edge devices to achieve real-time updates of on-site detection capabilities.
[0017] Furthermore, the model training module supports pausing, adjusting parameters, and continuing training midway to improve the learning effect on defect target features in newly added samples.
[0018] By employing the above technical solution, the present invention provides a method for detecting surface defects in bullet casings and an integrated platform for image training and inference, which has at least the following beneficial effects: (1) This invention significantly improves the robustness of the model to small defect targets and complex backgrounds by designing a dual enhancement strategy that combines Mosaic splicing and CopyPaste pasting; (2) This invention improves the matching rate of small defect targets and increases detection accuracy by using anchor re-clustering and adding small-sized anchors; (3) This invention improves the structure of the traditional YOLOv5 target detection model for defect detection tasks by introducing the P2 shallow detection head and CBAM mechanism into the constructed defect detection model, thereby enhancing the model's ability to extract features of small defects. (4) This invention effectively alleviates the problems of positive and negative sample imbalance and aspect ratio deviation of bounding boxes by introducing Focal Loss and AR-CIoU loss into the constructed defect detection model; (5) This invention achieves closed-loop management of the model from construction to field application by building an integrated platform for data acquisition, annotation, training and deployment; (6) The platform constructed in this invention supports continuous iteration and remote upgrades of the model, ensuring the stability and adaptability of the system in long-term operation. Attached Figure Description
[0019] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 This is a flowchart of a method for detecting surface defects in bullet casings according to the present invention; Figure 2 This is a schematic diagram illustrating the operation of the defect detection model constructed in this invention. Detailed Implementation
[0020] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. This will allow for a full understanding of how the present application uses technical means to solve technical problems and achieve technical effects, and to facilitate its implementation.
[0021] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0022] Please refer to Figures 1-2 This illustration shows a specific implementation of this embodiment. This embodiment extracts features of defect targets on the surface of bullet casings for anchor re-clustering, adaptively and dynamically adjusts the number, density, and size of anchor boxes, adds a shallow detection head and introduces the CBAM mechanism to improve the structure of the YOLOv5 target detection model, and introduces Focal Loss and AR-CIoU loss as loss functions, which significantly improves the detection effect of the constructed model on small defect targets. It also constructs an integrated platform for data acquisition, annotation, training, and deployment, realizing closed-loop management of the model from construction to field application.
[0023] Please refer to Figure 1 This embodiment proposes a method for detecting defects on the surface of bullet casings, which includes the following steps: S1. Acquire the original 360-degree images of the bullet casing, unfold and reconstruct them into a complete planar image, and perform preprocessing such as brightness normalization, contrast stretching, and edge enhancement to improve the salience of the defective target area. As a preferred embodiment of step S1, the specific process includes the following steps: S11. Use a high-resolution industrial camera to capture 360-degree surround images of the bullet casing to obtain its original images. Then, based on the central axis, unfold and reconstruct the original images to generate a complete planar image of the bullet casing surface, which serves as the original image. In this embodiment, a rotating platform or sliding rail is used to control the shooting angle, ensuring that the original shooting images of each bullet casing have consistent angles, lighting conditions and resolutions, so as to improve the stability and accuracy of subsequent identification.
[0024] S12. The original image may contain issues such as exposure differences and shadows. To improve the model's adaptability to the overall grayscale distribution of the image, brightness normalization is performed on the original image. Let the original image be... Normalized image The calculation method is as follows: ; in This represents the average grayscale value of the entire original image. The standard deviation is used. After normalization, the image gray levels are concentrated in the interval [−1,1], which helps the neural network model converge quickly.
[0025] S13. To further enhance the saliency of the defective target area, contrast stretching and edge enhancement are performed on the image after brightness normalization to highlight the visibility of small defective targets. In this embodiment, contrast stretching enhances the visibility of minor flaws (such as scratches and dents) by linearly expanding the image grayscale range; edge enhancement uses a Laplacian filter or a high-pass filter convolution kernel to process the image edges, making the defect contours clearer and facilitating subsequent feature extraction.
[0026] In this embodiment, after performing surround acquisition, brightness normalization, contrast stretching, and edge enhancement, the resulting schematic diagram can be found in the image. Figure 2 The upper left side; S2. A data augmentation strategy combining Mosaic stitching and CopyPaste is used to amplify the preprocessed images and obtain new training samples to improve the model's robustness in recognizing small defect targets in complex backgrounds. As a preferred embodiment of step S2, the specific process includes the following steps: S21. Given a preprocessed image, perform Mosaic stitching to augment its data, simulating defect behavior under different backgrounds and helping the model adapt to defect recognition in different environments; the specific operation of Mosaic stitching is as follows: assuming four images Each image is sized as follows: splice them together into a sheet The image, expressed as a formula, is as follows: ; in, This indicates a Mosaic splicing operation. The stitched image is a new image in which the defective target area appears in a new location and scene.
[0027] S22. The preprocessed image is processed using CopyPaste, which pastes the defective target region from one image to a random position in another image to generate a new image after pasting; the specific operation of CopyPaste is as follows: the defective target region is pasted from one image to another at a random position in another image. Extract from and paste into another image. The random position is expressed by the formula: ; in, The defective target area includes cracks or scratches on the bullet casing. This indicates the CopyPaste operation. This is the new image after pasting.
[0028] S23. The stitched new image and the pasted new image are fused together to generate enhanced training samples. The formula is expressed as: ; In this embodiment, the data augmentation strategy of combining Mosaic stitching and CopyPaste pasting enables the model to better adapt to the complexity of bullet casing surface defects, especially when the background is complex and the defects are small, thereby improving detection accuracy.
[0029] In this embodiment, a dual enhancement strategy combining Mosaic stitching and CopyPaste significantly improves the model's robustness to small defect targets and complex backgrounds. A schematic diagram of the Mosaic stitching and CopyPaste techniques can be found in [reference needed]. Figure 2 The upper middle part.
[0030] S3. Extract the features of the defect target on the bullet casing surface, the features including aspect ratio and area; perform logarithmic transformation and standardization on its area, and perform anchor re-clustering on the extracted features, increase the number of small-sized anchor boxes and adjust the aspect ratio and density of the anchor boxes, and dynamically update the size and number of anchor boxes according to the resolution of the feature map and the complexity of the defect target. As a preferred embodiment of step S3, the specific process includes the following steps: S31. Analyze and statistically analyze the width of the defects on the bullet casing surface. and height Extract the aspect ratio of the defective target. and area These features help to understand the shape of the defect and its requirements for Anchor box matching.
[0031] More specifically, in step S31, special attention is paid to the features of small defect targets (such as tiny cracks and tiny dents) so that the Anchor box can fit the small defect targets.
[0032] S32. Perform logarithmic transformation and standardization on the area to make the eigenvalues more evenly distributed and located on the same scale; the standardization formula is as follows: ; In the above formula, and These are the aspect ratio and the average area, respectively. and These are the aspect ratio and the standard deviation of the area, respectively. and These represent the aspect ratio and area after standardization, respectively.
[0033] S33. Anchor re-clustering is performed on the extracted features based on the K-Means++ clustering algorithm to optimize the anchor box size. The K-Means++ clustering algorithm can select initial cluster centers that are far from existing cluster centers, thereby improving the clustering effect and avoiding getting trapped in local optima. The goal of anchor re-clustering is to minimize the error between features. Assume the... The characteristics of each defective target are: , No. The size of each anchor box is Then we have: ; In the formula, This indicates a minimize operation. The number of clusters; For the first The number of samples in each cluster; For the first Cluster centers of each cluster.
[0034] S34. Surface defects in bullet casings often manifest as tiny, irregularly shaped defects located in relatively smooth areas. These small defect targets are easily overlooked by traditional anchor boxes. Therefore, increasing the number of small-sized anchor boxes can improve the detection accuracy of small defect targets and ensure that small cracks and minor flaws are not missed.
[0035] S35. On the other hand, cracks and dents on bullet casings often appear as long strips or irregular shapes. Therefore, adjust the aspect ratio of the Anchor box to accommodate the irregular shape of the defective target. S36. In addition, bullet casing defects usually have the characteristic of localized concentrated distribution. More anchor boxes should be allocated to the high-density areas of these defective targets to ensure that the defective targets are accurately detected. S37. The size of defects on the surface of bullet casings varies considerably, and due to differences in manufacturing processes and usage environments, defects of different scales may occur. Therefore, during model training, the anchor box configuration is dynamically updated: higher-resolution feature maps retain more detail, so smaller anchor boxes are used for them; lower-resolution feature maps better identify larger targets, so larger anchor boxes are used for them. Furthermore, the number of anchor boxes is dynamically adjusted based on the complexity of the defect target to accommodate its different shapes.
[0036] In this embodiment, applying a logarithmic transformation to the area can reduce the impact of large-sized defect targets on the anchor re-clustering process. By increasing the number of small-sized anchors through anchor re-clustering, the matching rate of small-sized defect targets is improved, thereby increasing detection accuracy. The process of increasing the number of small-sized anchors in this embodiment can be found in [reference needed]. Figure 2 On the upper right side, the Anchor re-clustering uses the K-means++ clustering algorithm to match suitable Anchor boxes for this detection task based on information such as size, instead of using the model's built-in size. On the other hand, the original model's built-in Anchor boxes are usually too large to fit small targets, so the algorithm adds smaller boxes to further refine the Anchors.
[0037] S4. Construct a defect detection model based on the YOLOv5 architecture, add a shallow detection head to the defect detection model and introduce the CBAM mechanism; As a preferred embodiment of step S4, the specific process includes the following steps: The S41 and YOLOv5 structures originally performed target detection in layers P3, P4, and P5. These layers process higher-level features and are suitable for detecting large targets. Layer P2, as a shallow layer, can capture richer high-frequency detail information, which is particularly important for detecting micro-cracks or small targets. Therefore, a shallow detection head is added to layer P2 of the YOLOv5 structure to specifically handle small-scale defects. Assume... This is the feature map for layer P2, which the model uses to generate detection results. ; in, These are the weight parameters of layer P2. It is a shallow detection head. The results obtained from the test.
[0038] S42. To improve the detection accuracy of YOLOv5 in handling small defect targets and complex backgrounds, a Convolutional Block Attention Module (CBAM) mechanism is introduced into the backbone feature extraction module of the YOLOv5 architecture. This enhances the model's ability to extract features from defect target regions. Specifically, CBAM is added after CSPlayer2 following the P2 layer of the backbone feature extraction module to enhance the model's focus on defect target regions in shallow feature maps and reduce background interference. The CBAM includes cascaded channel attention and spatial attention. Channel attention calculates the importance of each channel. ; In the above formula and These are the modified linear unit and the sigmoid activation function, respectively. This represents the input feature map extracted from CSPlayer2. For the first The kernel parameters of the convolution layer are: Channel attention features are used; subsequently, spatial attention calculates the importance of each spatial location: ; In the above formula This represents the convolution operation. Indicates spatial attention characteristics; Finally, the spatial attention features are compared with the input feature map. Perform feature fusion to obtain a fused feature map. As the output of CBAM: ; In this embodiment, the traditional YOLOv5 target detection model structure is improved for defect detection tasks. A P2 layer shallow detection head and CBAM mechanism are introduced into the constructed defect detection model to enhance the model's ability to extract features of small defects.
[0039] S5. Replace the original classification loss function and bounding box regression loss function of the YOLOv5 structure in the defect detection model with Focal Loss and AR-CIoU loss to improve the imbalance of positive and negative samples for small defect targets and improve the bounding box regression accuracy. As a preferred embodiment of step S5, the specific process includes the following steps: S51. To address the issue of extremely imbalanced positive and negative sample ratios during training for bullet casing defect targets, Focal Loss is used to replace the classification loss function in the original YOLOv5 structure. The expression is: ; In the formula, Indicates Focal Loss; For defect category weighting coefficients, Indicates the type of defect, such as "flat mouth", "shoulder wrinkles", "paint damage", etc. Adjustment factor for easy and difficult samples; This refers to the probability of the defect category predicted by the defect detection model. When the sample is easy to classify, Larger Approaching zero reduces the loss weight of that sample; Represents logarithmic calculation; In this embodiment, a difficulty-sample adjustment factor is introduced. and defect category weight coefficient This reduces the interference of a large number of easily classified negative samples on gradient updates, enhances the focus on difficult-to-classify defect samples, and thus improves the detection recall and accuracy of small defect targets.
[0040] S52. Design AR-CIoU (Aspect Ratio Complete IoU) loss as the bounding box regression loss function, and introduce the bounding box aspect ratio consistency constraint term into the CIoU loss function used in the original YOLOv5 structure. The expression is as follows: ; ; In the formula, This represents the designed AR-CIoU loss; Indicates intersection, union, and ratio; This indicates the difference in aspect ratio between the detection bounding box and the ground truth bounding box; This is a weighting factor; by adjusting this factor, the IoU and The importance of consistency; Represents the arctan operation; The distance between the center point of the detection box and the center point of the ground truth box; The diagonal length of the smallest closure region that can simultaneously contain both detection boxes and ground truth boxes; This represents the weighting coefficient used to balance the IoU loss and the aspect ratio consistency loss; This parameter represents the aspect ratio of the detection box and the ground truth box, and is used to measure the consistency of the aspect ratio. This is an angle parameter used to describe the angular relationship between the detection box and the ground truth box (in angle-related scenarios). The coordinates of the center point of the detection frame; The coordinates of the center point of the true bounding box; , These are the height and width of the detection frame, respectively; , These represent the height and width of the actual bounding box, respectively.
[0041] In this embodiment, by introducing a bounding box aspect ratio consistency constraint term on the basis of the original CIOU distance, overlap, and center point error, the deviation between the detection box and the real box in terms of aspect ratio is reduced, thereby obtaining a regression result that is more consistent with the shape of the bullet casing defect.
[0042] In this embodiment, by introducing Focal Loss and AR-CIoU loss into the constructed defect detection model, the problems of positive and negative sample imbalance and aspect ratio deviation of the bounding boxes are effectively alleviated. A schematic diagram illustrating the introduction of a shallow detection head and CBAM mechanism for feature fusion, along with the introduction of Focal Loss and AR-CIoU loss to improve the traditional YOLOv5 structure, can be found here. Figure 2 On the lower side, the target confidence loss is the original BEC loss of the YOLOv5 structure.
[0043] This application embodiment also provides an integrated training and inference platform for bullet casing surface defect images, used to apply the bullet casing surface defect detection method, including: a project management module, a dataset management module, a sample amplification module, a training configuration interface, a model training module, a training task monitoring interface, a model evaluation module, and a deployment management module. The project management module allows you to create or open an existing defect detection project and select an initial defect detection model and the corresponding dataset version as the training basis. The dataset management module expands, reconstructs, and preprocesses the newly acquired original images of bullet casings, uploads them as additional images, and labels them with defect categories, so that they can participate in subsequent iterative training as new samples. Before iterative training, the module automatically performs dataset checks, performs integrity checks, sample counts, and label consistency checks on the training set, validation set, and test set after adding new samples. The sample augmentation module applies a data augmentation strategy that combines Mosaic splicing and CopyPaste pasting to the training set, validation set, and test set after adding new samples, for subsequent training of the defect detection model. The training configuration interface allows users to select between full training mode and incremental training mode. In incremental training mode, the platform fine-tunes the weights based on the parameters of the original defect detection model, retains the existing feature learning results, and incorporates the feature information of newly added samples. At the same time, this interface allows users to adjust the number of training rounds, learning rate, optimizer type, data augmentation strategy, and loss function configuration. The model training module is used to perform Anchor re-clustering, adjust the number of small-sized Anchor boxes, and adjust the aspect ratio, density, size, and number of Anchor boxes. At the same time, the module has built-in training clusters or cloud computing resources, and iteratively trains the defect detection model based on Focal Loss and AR-CIoU loss. It supports multi-GPU parallelism and breakpoint resume training, and records various training indicators in real time during the training process. More specifically, the model training module supports pausing, adjusting parameters, and continuing training midway to improve the learning effect on the defect target features in newly added samples; The training task monitoring interface dynamically displays various training indicators recorded in real time during the training process. The model evaluation module generates an updated model evaluation report after the defect detection model has been iteratively trained. It compares the performance changes of the old and new defect detection models on the test set and new samples, and binds and archives the trained model file, training configuration, dataset version and evaluation results to ensure that the iteration process is traceable. The deployment management module pushes the trained defect detection model to edge devices to achieve real-time updates of on-site detection capabilities.
[0044] In this embodiment, by constructing an integrated platform for data acquisition, annotation, training, and deployment, closed-loop management of the model from construction to field application is achieved. The constructed platform supports continuous iteration and remote upgrades of the model, ensuring the stability and adaptability of the system in long-term operation.
[0045] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of those different embodiments or examples.
[0046] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).
[0047] The above embodiments provide a detailed description of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for detecting surface defects in bullet casings, characterized in that, Includes the following steps: S1. Acquire the original 360-degree images of the bullet casing, unfold and reconstruct them into a complete planar image, and perform preprocessing such as brightness normalization, contrast stretching, and edge enhancement. S2. A data augmentation strategy combining Mosaic stitching and CopyPaste is used to amplify samples in the preprocessed images to obtain enhanced training samples, thereby improving the model's robustness in recognizing small defect targets in complex backgrounds. S3. Extract the features of the defect target on the bullet casing surface, the features including aspect ratio and area; perform logarithmic transformation and standardization on its area, and perform anchor re-clustering on the extracted features, increase the number of small-sized anchor boxes and adjust the aspect ratio and density of the anchor boxes, and dynamically update the size and number of anchor boxes according to the resolution of the feature map and the complexity of the defect target. S4. Construct a defect detection model based on the YOLOv5 architecture, add a shallow detection head to the defect detection model and introduce the CBAM mechanism; S5. Replace the original classification loss function and bounding box regression loss function of the YOLOv5 structure in the defect detection model with Focal Loss and AR-CIoU loss to improve the imbalance of positive and negative samples for small defect targets and improve the accuracy of bounding box regression.
2. The method for detecting surface defects in a bullet casing according to claim 1, characterized in that: Step S1 specifically includes the following steps: S11. Use a high-resolution industrial camera to capture 360-degree surround images of the bullet casing to obtain its original images. Then, based on the central axis, unfold and reconstruct the original images to generate a complete planar image of the bullet casing surface, which serves as the original image. S12. Perform brightness normalization processing on the original image to make its gray level concentrated in the interval [−1,1]. S13. Perform contrast stretching and edge enhancement on the image after brightness normalization to highlight the visibility of small defect targets.
3. The method for detecting surface defects in a bullet casing according to claim 1, characterized in that: Step S2 specifically includes the following steps: S21. Given a preprocessed image, use Mosaic stitching to perform data augmentation on it, generating a new stitched image to simulate the defect behavior under different backgrounds; S22. Use CopyPaste to process the preprocessed image, paste the defective target area from one image to a random position in another image, and generate a new image after pasting. S23. Merge the stitched new image and the pasted new image to generate enhanced training samples.
4. The method for detecting surface defects in a bullet casing according to claim 1, characterized in that: Step S3 specifically includes the following steps: S31. Analyze and statistically analyze the width and height of the defect targets on the bullet casing surface, and extract the aspect ratio and area of the defect targets; S32. Perform logarithmic transformation and standardization on the area to make the eigenvalues more evenly distributed and located on the same scale. S33. Based on the K-Means++ clustering algorithm, the extracted features are re-clustered using Anchors to optimize the size of the Anchor boxes; S34. Increase the number of small-sized anchor boxes to improve the detection accuracy of small defect targets; S35. Adjust the aspect ratio of the Anchor box to accommodate the irregular shape of the defective target; S36. Assign more anchor boxes to high-density areas of defective targets to ensure that defective targets are detected accurately. S37. During model training, the Anchor box configuration is dynamically updated. Smaller Anchor boxes are used for higher resolution feature maps, and larger Anchor boxes are used for lower resolution feature maps. The number of Anchor boxes is also dynamically adjusted according to the complexity of the defect target to adapt to different shapes of the defect target.
5. The method for detecting surface defects in a bullet casing according to claim 4, characterized in that: In step S31, special attention is paid to the features of small defect targets so that the Anchor box can fit the small defect targets.
6. The method for detecting surface defects in a bullet casing according to claim 1, characterized in that: Step S4 specifically includes the following steps: S41. Add a shallow detection head to the P2 layer of the YOLOv5 structure to specifically handle small-scale defect targets; S42. Introduce the CBAM mechanism into the backbone feature extraction module of the YOLOv5 architecture to enhance the model's ability to extract features from defect target regions.
7. The method for detecting surface defects in a bullet casing according to claim 1, characterized in that: Step S5 specifically includes the following steps: S51. Replace the classification loss function in the original YOLOv5 structure with Focal Loss, the expression of which is: ; In the formula, Indicates Focal Loss; For defect category weighting coefficients, Indicates the defect category; Adjustment factor for easy and difficult samples; This refers to the probability of the defect category predicted by the defect detection model. When the sample is easy to classify, Larger Approaching zero reduces the loss weight of that sample; Represents logarithmic calculation; S52. Design the AR-CIoU loss as the bounding box regression loss function, and introduce the bounding box aspect ratio consistency constraint term into the CIoU loss function used in the original YOLOv5 structure. The expression is as follows: ; ; In the formula, This represents the designed AR-CIoU loss; Indicates intersection, union, and ratio; This indicates the difference in aspect ratio between the detection bounding box and the ground truth bounding box; This is a weighting factor; by adjusting this factor, the IoU and The importance of consistency; Represents the arctan operation; The distance between the center point of the detection box and the center point of the ground truth box; The diagonal length of the smallest closure region that can simultaneously contain both detection boxes and ground truth boxes; This represents the weighting coefficient used to balance the IoU loss and the aspect ratio consistency loss; This parameter represents the aspect ratio of the detection box and the ground truth box, and is used to measure the consistency of the aspect ratio. This is an angle parameter used to describe the angular relationship between the detection box and the ground truth box; The coordinates of the center point of the detection frame; The coordinates of the center point of the true bounding box; , These are the height and width of the detection frame, respectively; , These represent the height and width of the actual bounding box, respectively.
8. A bullet casing surface defect image training and inference integrated platform, used for applying the bullet casing surface defect detection method as described in any one of claims 1-7, characterized in that, include: Project management module, dataset management module, sample augmentation module, training configuration interface, model training module, training task monitoring interface, model evaluation module, deployment management module; The project management module allows you to create or open an existing defect detection project and select an initial defect detection model and the corresponding dataset version as the training basis. The dataset management module expands, reconstructs, and preprocesses the newly acquired original images of bullet casings, uploads them as additional images, and labels them with defect categories, so that they can participate in subsequent iterative training as new samples. Before iterative training, the module automatically performs dataset checks, performs integrity checks, sample counts, and label consistency checks on the training set, validation set, and test set after adding new samples. The sample augmentation module applies a data augmentation strategy that combines Mosaic splicing and CopyPaste pasting to the training set, validation set, and test set after adding new samples, for subsequent training of the defect detection model. The training configuration interface allows users to select between full training mode and incremental training mode. In incremental training mode, the platform fine-tunes the weights based on the parameters of the original defect detection model, retains the existing feature learning results, and incorporates the feature information of newly added samples. At the same time, this interface allows users to adjust the number of training rounds, learning rate, optimizer type, data augmentation strategy, and loss function configuration. The model training module is used to perform Anchor re-clustering, adjust the number of small-sized Anchor boxes, and adjust the aspect ratio, density, size, and number of Anchor boxes. At the same time, the module has built-in training clusters or cloud computing resources, and iteratively trains the defect detection model based on FocalLoss and AR-CIoU loss. It supports multi-GPU parallelism and breakpoint resume training, and records various training indicators in real time during the training process. The training task monitoring interface dynamically displays various training indicators recorded in real time during the training process. The model evaluation module generates an updated model evaluation report after the defect detection model has been iteratively trained. It compares the performance changes of the old and new defect detection models on the test set and new samples, and binds and archives the trained model file, training configuration, dataset version and evaluation results to ensure that the iteration process is traceable. The deployment management module pushes the trained defect detection model to edge devices to achieve real-time updates of on-site detection capabilities.
9. The integrated training and inference platform for bullet casing surface defect images according to claim 8, characterized in that: The model training module supports pausing, adjusting parameters, and continuing training midway to improve the learning effect on defect target features in newly added samples.
Citation Information
Patent Citations
Pomegranate fruit detection method before fruit thinning based on improved YOLOv8s
CN116958962A
Shaving board surface defect detection method and device based on improved YOLOv5
CN117058077A
Semantic segmentation-based method for polishing surface defects of medium and thick plate by robot
CN117408970A
Ammunition surface detection method, system, equipment and medium
CN118887184A
Industrial part defect detection method based on improved YOLOv8 model
CN118967602A