Lightweight detection method and system for surface defects of cartridge case
By combining multispectral image fusion and lightweight feature extraction networks with capsule networks, the problems of high false negative rate, high computational complexity and poor environmental adaptability in shell surface defect detection are solved, and efficient and accurate shell surface defect detection is achieved.
Patent Information
- Application Number
- CN202511367438.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2025-09-12
- Filing Date
- 2025-09-23
- Publication Date
- 2026-01-09
AI Technical Summary
Existing surface defect detection technologies for cartridge cases are unable to fully capture complex defect features, have a high rate of missed detection of latent defects, have a large number of model parameters, high computational complexity, and poor environmental adaptability, and cannot meet the needs of high-speed detection and dynamic adjustment.
A combined approach of multispectral image fusion, lightweight feature extraction network, and capsule network is adopted, including dynamic weight fusion algorithm, feature extraction network, multi-scale segmentation, and capsule network-based hybrid classifier, to achieve efficient identification of surface defects in cartridge cases.
It improves the detection rate of latent defects to 99.5%, reduces the false negative rate to 0.5%, reduces the number of parameters by 56%, reduces the detection time per frame to 8ms, reduces the accuracy fluctuation to less than 0.3% when the ambient light fluctuates, and shortens the model update cycle to 1 week, meeting the needs of high-speed detection and dynamic adjustment.
Smart Images

Figure CN121305162A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to a bullet mass detection technology field, in particular to a shell surface defect lightweight detection method and system. BACKGROUND
[0002] Shell surface defect detection is a core link of ammunition production quality control, and is directly related to the combat effectiveness and safety of weapon systems. There are three major problems in current detection technology: first, the existing machine vision method is difficult to fully capture complex defect features such as scratches and micro-cracks, resulting in a hidden defect omission rate of more than 8%; second, the mainstream detection model uses a fixed structure convolutional neural network, with a parameter quantity generally exceeding 50 million, requiring high-performance GPU hardware support, and the single-frame image processing time exceeds 40 ms, which cannot meet the high-speed detection demand of 160 shells per minute on the production line; third, the environmental adaptability is poor, and the detection accuracy decreases by 10% to 15% under the conditions of light change ±20% or oil pollution interference, and the model updating cycle is long, which is difficult to quickly respond to the detection demand of new defects. SUMMARY
[0003] In order to solve at least one of the above problems, the application provides a shell surface defect lightweight detection method and system.
[0004] In a first aspect, the application provides a shell surface defect lightweight detection method:
[0005] The shell surface defect lightweight detection method comprises:
[0006] Obtaining a visible light image, a near-infrared image and a polarization image corresponding to a to-be-detected shell, and generating an enhanced image by using a dynamic weight fusion algorithm;
[0007] Performing dynamic feature extraction on the enhanced image by using a feature extraction network;
[0008] Segmenting the extracted feature map to obtain a defect region by using a multi-scale segmentation, and identifying a defect type corresponding to the defect region by using a lightweight hybrid classifier based on a capsule network, and outputting an identification result.
[0009] Optionally, the dynamic weight fusion algorithm comprises:
[0010] Calculating a fusion weight corresponding to each of the visible light image, the near-infrared image and the polarization image;
[0011] Performing normalization processing on the fusion weight corresponding to each, so that the normalized fusion weight value is limited in the range of (0, 1), and the sum of the normalized fusion weights is 1;
[0012] Based on the normalized fusion weight, the visible light image, the near-infrared image and the polarization image are weighted and summed to obtain the enhanced image.
[0013] Optionally, the calculating the fusion weight corresponding to each of the visible light image, the near-infrared image and the polarization image comprises:
[0014] The fusion weight w1 corresponding to the visible light image is calculated according to a texture definition index T1, and the calculation formula is: w1 = 0.4 + 0.1 x T1, wherein the texture definition index T1 is a gradient amplitude standard deviation corresponding to the visible light image.
[0015] The fusion weight w2 corresponding to the near-infrared image is calculated according to an infrared response intensity T2, and the calculation formula is: w2 = 0.3 + 0.1 x T2, wherein T2 is an average gray value corresponding to the near-infrared image.
[0016] The fusion weight w3 corresponding to the polarization image is calculated according to a polarization difference degree T3, and the calculation formula is: w3 = 0.3 + 0.1 x T3; wherein T3 is a multi-angle intensity variance corresponding to the polarization image.
[0017] Optionally, the feature extraction network is based on a ShuffleNetV2 architecture, removes a 1x1 convolution layer in the original ShuffleNetV2 network, and includes four convolution blocks, each of which includes a grouped convolution, a channel shuffle and a down-sampling; and a dynamic attention mechanism module is embedded between the convolution blocks, with the output end of each convolution block as an embedding point, the dynamic attention mechanism module includes a spatial attention branch and a channel attention branch, the spatial attention branch is used to generate a spatial weight, and the channel attention branch is used for channel pruning.
[0018] Optionally, the channel attention branch is used to calculate the gradient mean μ g and the standard deviation σ g of all channels, a dynamic threshold θ is calculated according to the formula θ = μ g + 0.5 x σ g , if the μ g,c of a certain channel is less than θ, it is determined as a redundant channel, the redundant channel is directly set to zero, only the effective channel with μ g,c ≥ θ is reserved, and a channel normalization weight is calculated for the effective channel to enhance the feature sharing of the effective channel.
[0019] Optionally, the method further includes: optimizing network performance using a dual-teacher knowledge distillation strategy, with ResNet101 (precision teacher) and EfficientNet-B4 (efficiency teacher) as a joint teacher model; the feature extraction network as a student model, achieving knowledge transfer by minimizing KL divergence loss and feature distillation loss, with the distillation temperature parameter linearly decreasing from 5 to 2, decreasing by 0.0375 per training round.
[0020] Optionally, the step of segmenting the extracted feature map using multi-scale segmentation to obtain the defect region includes:
[0021] Convert the extracted feature map into a grayscale image;
[0022] Calculate the local entropy H(S) for different window sizes for a grayscale image:
[0023]
[0024] In the formula, p k This represents the proportion of pixels with gray level k within the window to the total number of pixels in the window.
[0025] Calculate the information entropy gain G(S) based on the local entropy H(S) corresponding to different window sizes:
[0026] G(S)=H(S)-[H(sprev)+H(snext)] / 2
[0027] The scale S∈{3,5,7};
[0028] When S = 3, the formula for calculating the information entropy gain G(S) is G(3) = H(3) - H(5);
[0029] When S = 5, the formula for calculating the information entropy gain G(S) is G(5) = H(5) - [H(3) + H(7)] / 2;
[0030] When S = 7, the formula for calculating the information entropy gain G(S) is G(7) = H(7) - H(5);
[0031] For each pixel, the window with the largest G(s) size is selected as the optimal segmentation scale for that pixel;
[0032] The local threshold Tentropy is calculated based on the local entropy H(S) under the optimal segmentation scale.
[0033] Combining the globally optimal threshold Totsu, the segmentation threshold T is calculated using the following formula:
[0034] T = 0.7 × Totsu + 0.3 × Tentropy
[0035] The grayscale image is binarized based on the segmentation threshold T. If the grayscale value is greater than T, it is determined to be a defective pixel. The connected region whose area reaches the set area threshold is retained as the effective defect region.
[0036] Optionally, the step of using a lightweight hybrid classifier based on capsule networks to identify the defect type corresponding to the defect region includes:
[0037] Geometric topological features and depth texture features are extracted from the input defect region. The extracted geometric topological features and depth texture features are then concatenated and fused to form a hybrid feature. This hybrid feature is then input into a capsule network and outputs the corresponding defect type.
[0038] Optionally, the capsule network includes:
[0039] The input layer is used to convert the mixed features into an output of 64 neurons.
[0040] The primary capsule layer, used to convert scalars into vectors, consists of 32 capsules, each of which is an 8-dimensional vector.
[0041] The digital capsule layer consists of 6 capsules, each of which is a 16-dimensional vector corresponding to 6 defect types. By calculating the magnitude of the output vector of each digital capsule, the Squashing function is used to compress the magnitude to between 0 and 1, outputting a 6-dimensional probability vector, and taking the maximum value as the recognition result.
[0042] Secondly, this application provides a lightweight detection system for surface defects in cartridge cases; the system includes modules for performing the lightweight detection method for surface defects in cartridge cases as described in the first aspect or any possible implementation thereof:
[0043] This lightweight defect detection system for cartridge cases includes:
[0044] The acquisition module is used to acquire the visible light image, near-infrared image, and polarization image of the shell to be detected;
[0045] The fusion preprocessing module is used to generate enhanced images using a dynamic weight fusion algorithm;
[0046] The feature extraction module is used to dynamically extract features from the enhanced image using a feature extraction network;
[0047] The multi-scale segmentation module is used to segment the extracted feature map using multi-scale segmentation to obtain the defect region;
[0048] The classification module is used to identify the defect type corresponding to the defect region using a lightweight hybrid classifier based on capsule networks, and output the identification results.
[0049] Thirdly, this application provides a computer device including a processor, a memory, and a communication bus, wherein the communication bus is used to realize a communication connection between the processor and the memory, and the processor is used to execute a computer program stored in the memory to implement the lightweight detection method for surface defects of cartridge cases as described in any of the preceding claims.
[0050] Fourthly, this application also provides a computer-readable storage medium storing a computer program; the computer program can be executed by a processor to implement the lightweight detection method for surface defects of cartridge cases as described above.
[0051] Fifthly, this application also provides a computer program product, including a computer program that can be executed by a processor to implement the lightweight detection method for surface defects of cartridge cases as described above.
[0052] This application includes at least the following beneficial technical effects:
[0053] 1. By using normalized weight fusion and polarization mode, the detection rate of latent defects is increased to 99.5%, and the false negative rate is reduced to 0.5%, which comprehensively solves the problem of incomplete capture of complex defect features.
[0054] 2. By using gradient graph spatial attention and adaptive pruning, the number of parameters is reduced by 56% compared to MobileNetV3, and the detection time per frame is reduced to 8ms, meeting the high-speed detection requirements of the production line.
[0055] The 3.6×16D capsule network achieves 99.5% accuracy, with accuracy fluctuation of <0.3% when illumination fluctuation is ±30%, thus solving the problem of poor environmental adaptability.
[0056] 4. Process feedback and incremental training shorten the model update cycle to one week and improve the response speed of new defect identification by 70%, meeting the dynamic adjustment needs of flexible production. Attached Figure Description
[0057] Figure 1 A schematic diagram of a lightweight detection system for surface defects in a cartridge case provided in this application embodiment;
[0058] Figure 2 A schematic flowchart of a method for lightweighting detection of surface defects in a projectile casing provided in this application embodiment;
[0059] Figure 3 This is a schematic diagram of a feature extraction network structure provided in an embodiment of this application;
[0060] Figure 4 This is a schematic diagram of another feature extraction network structure provided in an embodiment of this application;
[0061] Figure 5 This application provides a schematic diagram of a multi-scale entropy segmentation process.
[0062] Figure 6 A schematic diagram of a lightweight hybrid classifier structure based on capsule networks is provided for an embodiment of this application;
[0063] Figure 7 This application provides a schematic diagram of a closed-loop feedback optimization process.
[0064] Figure 8 A schematic diagram of an MLP model architecture provided in this application embodiment;
[0065] Figure 9 A schematic diagram of another lightweight detection system for surface defects in cartridge cases provided in this application embodiment;
[0066] Figure 10 This is a schematic diagram of a computer device structure provided in an embodiment of this application. Detailed Implementation
[0067] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0068] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to and includes any or all possible combinations of one or more of the listed items. The term “exemplary” means “serving as an example, embodiment, or illustration,” and any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments. The terms “first” and “second” are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as “first” or “second” may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, “a plurality” means two or more.
[0069] refer to Figure 1This application provides a lightweight detection system for surface defects in projectile casings, including a multispectral acquisition device, a fusion preprocessing module, a feature extraction network, a multi-scale segmentation module, and a hybrid classifier. The multispectral acquisition device is used to simultaneously acquire multispectral images of the projectile casing to be inspected, including visible light images, near-infrared images, and polarization images. The fusion preprocessing module is used to generate enhanced images using a dynamic weighted fusion algorithm. The feature extraction network is used to dynamically extract features from the enhanced images. The multi-scale segmentation module is used to segment the extracted feature maps to obtain defect regions. The hybrid classifier is used to identify the defect type corresponding to the defect region and output the identification result.
[0070] refer to Figure 2 Based on the aforementioned lightweight detection system for surface defects in cartridge cases, a corresponding lightweight detection method for surface defects in cartridge cases is provided, which mainly includes the following steps:
[0071] S102: Deploy testing hardware on the production line;
[0072] A system was deployed at the inspection station of a cartridge case production line. The multispectral acquisition equipment consisted of a Basler Ace 2 visible light camera (8ms exposure, 640×480 resolution, 30fps), a Xenics Bobcat near-infrared camera (6ms integration time, 640×480 resolution, 30fps), and a FLIR BFS-PGE polarization camera (0° / 45° / 90° / 135° polarization angle, 640×480 resolution, 25fps), forming a camera array. Millisecond-level synchronous acquisition was achieved through a synchronous trigger controller. The mechanical calibration error was controlled within 0.5 pixels. The lens focal length was 16mm, the installation height was 600mm, and the field of view covered an area of 100×80mm.
[0073] The main control device uses the NVIDIA Jetson Xavier NX embedded platform with 8GB of memory; it is equipped with a TSL2591 light sensor (accuracy ±50 lux) and an SHT30 temperature and humidity sensor (accuracy ±0.5℃).
[0074] The data processing module integrates algorithms for dynamic fusion preprocessing, dynamic feature extraction, multi-scale segmentation and classification, and closed-loop feedback optimization. It is built on the TensorFlow Lite framework. The dynamic attention mechanism module is accelerated by CUDA, multi-scale entropy calculation is accelerated by parallel processing, and capsule network is accelerated by TensorRT quantization.
[0075] S104: Multispectral fusion preprocessing to generate enhanced images;
[0076] Visible light, near-infrared and polarization images of the cartridge case are acquired simultaneously using a multispectral camera array. Enhanced images are generated by a dynamic weight fusion algorithm after feature point registration.
[0077] Visible light images are used to present surface texture features, near-infrared images enhance the detection of internal cracks, and polarized images highlight dent-like defects. Visible light images utilize the visible light band (400–760 nm, perceptible to the human eye) to capture the reflection / absorption signals of visible light on the cartridge case surface; they can capture surface texture, color differences, obvious scratches (such as visible scratches > 0.5 mm in length), and the distribution of surface stains; they can identify directly visible defects, providing a basic texture reference for defect localization, such as obvious scratches, dents, and missing text / markings on the cartridge case surface.
[0078] Near-infrared imaging mainly utilizes the near-infrared band (760–2500 nm) to capture the transmission / reflection signals of near-infrared light on the surface and shallow interior of the cartridge case. This allows for the detection of internal microcracks (such as latent cracks with a width > 0.1 mm) and areas of uneven material density (where near-infrared light can penetrate the surface). It also detects latent internal defects that are not visible to the naked eye, compensating for the blind spots of visible light in capturing deep defects, such as microcracks that have not penetrated the cartridge case wall and tiny pores left over from casting.
[0079] Polarization imaging utilizes the polarization characteristics of light (differences in the reflection angle and intensity of polarized light from different defect surfaces) to capture signals of polarization state changes; it can detect dent-like defects (such as tiny dents and indentations on the surface of cartridge cases), differences in the thickness of the surface oxide layer (different polarized light reflection intensities); it can identify dent-like defects with subtle protrusions and distinguish stains from real defects (stains have little effect on polarized light), such as tiny dents and minor local deformations on the surface of cartridge cases caused by impact.
[0080] In this embodiment, the registration algorithm uses the ORB (Oriented FAST and Rotated BRIEF) feature matching algorithm to register the multispectral image, with the registration error controlled within 1 pixel. Optionally, any existing method can be used for registration, as long as it can register the visible light image, near-infrared image, and polarization image, facilitating subsequent fusion processing.
[0081] In this embodiment, a dynamic weighted fusion algorithm is used to fuse the registered visible light image, near-infrared image, and polarization image. The fusion weight w1 of the visible light image is calculated based on the texture sharpness index T1, specifically as follows: w1 = 0.4 + 0.1 × T1. The texture sharpness index T1 is the standard deviation of the gradient magnitude of the visible light image, reflecting the dispersion of pixel grayscale gradients in the image. The greater the gradient difference (e.g., at scratches or edges), the higher the T1 value, which characterizes the response intensity of the visible light mode to visible defects on the surface of the cartridge case. Specifically, it can be calculated using the following Sobel operator:
[0082] First, calculate the Sobel gradient: For a visible light image (with dimensions M×N, pixel coordinates (i,j), and grayscale value I...),... vis (i,j)) use the 3x3 Sobel operator to calculate the gradients in the x-direction (horizontal) and y-direction (vertical) respectively:
[0083] Gradient G in the x-direction x (i,j): G x =Sobel x *I vis ,in
[0084] y-direction gradient G y (i,j): G y =Sobel y *I vis ,in
[0085] In the formula, the symbol "*" represents the convolution operation, which iterates through all pixels of the image to calculate the gradient.
[0086] Then calculate the standard deviation of the gradient magnitude:
[0087] Gradient magnitude of a single pixel:
[0088]
[0089] T1 (Standard deviation of gradient magnitude):
[0090]
[0091] In the formula,
[0092]
[0093] The average gradient magnitude of all pixels; M×N is the total number of pixels in the visible light image.
[0094] The near-infrared image fusion weight w2 is calculated based on the infrared response intensity T2, specifically using the formula: w2 = 0.3 + 0.1 × T2, where T2 is the average grayscale value of the near-infrared image; let the size be M × N, the pixel coordinates be (i, j), and the grayscale value be I. nir (i,j), then:
[0095]
[0096] The polarization image fusion weight w3 is calculated based on the polarization difference degree T3, specifically using the formula: w3 = 0.3 + 0.1 × T3; where T3 is the multi-angle intensity variance of the polarization image, reflecting the difference in reflection intensity of polarized light at different locations on the surface of the cartridge case for multiple angles (0° / 45° / 90° / 135°, a total of 4 angles). Defects such as depressions and oxide layers can increase the difference in polarization light reflection. T3 can characterize the response intensity of the polarization mode to the minute morphological defects of the cartridge case. Specifically, it can be calculated as follows:
[0097] First, calculate the average grayscale value of a single image from multiple angles: Assume the polarization image contains K = 4 angles (k = 1 corresponds to 0°, k = 2 corresponds to 45°, k = 3 corresponds to 90°, k = 4 corresponds to 135°), the image size is M × N, and the grayscale value of pixel (i, j) at the k-th angle is I. pol,k If (i,j), then the average gray level of a single pixel (i,j) from multiple angles is:
[0098]
[0099] Then calculate the multi-angle intensity variance:
[0100]
[0101] In the formula,
[0102]
[0103] Right now This represents the overall mean of the grayscale values of all pixels from multiple angles.
[0104] The calculated fusion weights are normalized so that the normalized fusion weight values are limited to the range (0,1). The specific formula is: w' i =wi / (w1+w2+w3), thus obtaining the normalized fusion weight w'1 corresponding to the visible light image, the normalized fusion weight w'2 corresponding to the near-infrared image, and the normalized fusion weight w'3 corresponding to the polarized image; and w'1+w'2+w'3=1, ensuring that the sum of the normalized weights is 1, avoiding abnormal overall brightness of the fused image.
[0105] Further, by utilizing the normalized fusion weights corresponding to each image, the images are fused, that is, the enhanced I is generated by weighted summation of the images. fuse (i,j), the gray value of each pixel in the image, is obtained by weighted summing of the gray values of the corresponding pixels in the three modal images according to the normalized fusion weights. The calculation formula is:
[0106] I fuse (i,j)=w ' 1×I vis (i,j)+w ' 2×I nir (i,j)+w ' 3×I pol (i,j)
[0107] Where (i,j) represents the image pixel coordinates (i for horizontal direction and j for vertical direction), covering all pixels of the image (all three image resolutions are 640×480, so i ranges from 0 to 639, and j ranges from 0 to 479); I vis (i,j) represents the gray value (0-255, reflecting the brightness of the surface texture at that location) in the visible light image; I nir (i,j) represents the gray value (0-255) of the near-infrared image at (i,j), reflecting the brightness of the internal structure at that location; for example, the gray value of a microcrack area will differ from that of a normal area. pol (i,j) represents the gray value of the polarization image at (i,j) (0~255, reflecting the surface morphology difference at this location, such as the gray value of the concave area will differ from the surrounding area); this scheme accurately superimposes the texture of visible light, the internal defects of near infrared, and the morphological defects of polarization by assigning dynamic weights pixel by pixel, thereby enhancing the defect features and reducing the false negative rate.
[0108] In optional embodiments of this application, dynamic window guided filtering can be used to perform lightweight noise reduction on the enhanced image, and Canny edge detection (gradient threshold 50-150) can be used to distinguish regions: the window size for smooth regions is 11×11, and the window size for edge regions is automatically reduced to 3×3; the specific processing can be flexible to better improve image quality and facilitate subsequent feature extraction and defect segmentation and recognition.
[0109] S106: Dynamic feature extraction of enhanced images using a feature extraction network;
[0110] refer to Figures 3-4In this embodiment, the feature extraction network is built on the ShuffleNetV2 architecture, embedding a dynamic attention mechanism module containing spatial and channel attention branches between convolutional layers. The spatial attention branch generates spatial weights based on the gradient map of the input augmented image (supervised by a teacher model heatmap during training), while the channel attention branch achieves dynamic channel selection through feature gradient evaluation of the input augmented image, setting an adaptive threshold: θ = μ. g +0.5×σ g (μ g σ is the mean of the channel gradient. g The channels are pruned in real time (to the standard deviation), with a pruning ratio dynamic range of 15% to 35%. A dual-teacher knowledge distillation strategy is adopted to optimize network performance, with ResNet101 as the precision teacher and EfficientNet-B4 as the efficiency teacher as the joint teacher model. The distillation process is executed offline on the server side. The student model achieves knowledge transfer by minimizing the KL divergence loss and feature distillation loss. The distillation temperature parameter is linearly reduced from 5 to 2 (reduced by 0.0375 per training round).
[0111] Specifically, the ShuffleNetV2-1.0 version with a smaller number of native parameters can be selected, which is better adapted to embedded platforms. The input is the enhanced image with a pixel size of 416×416 output from step S104. The image is passed through 4 customized convolutional blocks in sequence, and the output features are feature maps with 128 channels.
[0112] The core operations of each convolutional block include group convolution, channel shuffle, and downsampling: the input channels are divided into several groups (e.g., 8 groups), and convolution operations are performed within each group. This significantly reduces the number of parameters and computational cost, forming the cornerstone of lightweight models. One side effect of group convolution is the lack of information flow between groups. Channel shuffle effectively promotes information exchange between different groups by rearranging the channels, ensuring the integrity of the features. After the 2nd and 3rd convolutional blocks, a convolution operation with a stride of 2 halves the feature map size (length and width) while increasing the number of channels. In this way, the network gradually extracts multi-level information from the image, ranging from shallow texture features (such as edges and corners) to deep semantic features (such as crack morphology and scratch contours).
[0113] This approach removes the redundant 1×1 convolutional layers from the native ShuffleNetV2-1.0 network, thereby reducing computation by 30%. It retains only the core structures such as the grouped convolutional layers (number of groups = 8) and the feature shuffling layer, keeping 4 convolutional blocks. Each convolutional block contains 2 layers of 3×3 grouped convolutions. The grouped convolutions can reduce redundant computation between channels, while ensuring that multi-scale features of cartridge case defects, from shallow texture to deep semantics, can be captured under the premise of lightweight design. The feature shuffling layer can solve the channel isolation problem caused by the grouped convolutions, ensuring that features of small components such as scratches and microcracks on the cartridge case surface can be transferred across channels.
[0114] Meanwhile, a dynamic attention mechanism module is embedded between convolutional layers to enhance defective features at each stage of feature extraction, avoiding early features being interfered with by noise and later features being submerged by background information; specifically, the output end of each convolutional block can be selected as the embedding point.
[0115] In this embodiment, the spatial attention branch can be executed offline on the server during the training phase, and after training is completed, it can be deployed to an embedded platform to perform inference in real time, so as to better utilize the server's computing resources and improve training efficiency.
[0116] Specifically, during the training phase, the grayscale gradient map of the feature map output by the current convolutional block (e.g., the 64-channel feature map output by the first convolutional block) is calculated (using the Sobel operator, consistent with the gradient logic of calculating T1 in step S104), and high gradient regions are initially marked as defect regions. The defect heatmap of the teacher model ResNet101 is introduced as a supervision signal, and its heatmap and the current gradient map are optimized by mean squared error (MSE) loss. The weight generation logic of the spatial attention branch is trained to ensure that the final spatial weights can accurately cover the defect regions (e.g., scratch and crack location weights > 0.8, background region weights < 0.2).
[0117] During the inference phase, a 3×3 mean filter can be used to replace the Sobel operator, enabling real-time computation of low-complexity gradient maps on the feature maps output by the convolutional blocks, thus reducing computation time (as low as <0.5ms). The gradient map is converted into a 0-1 spatial weight matrix using the Sigmoid activation function; the feature map is then multiplied element-wise with the spatial weight matrix to enhance the features of defective regions and suppress background noise (e.g., background region features are weakened after multiplying by 0.2, while defective region features are enhanced after multiplying by 0.8).
[0118] For different input images (e.g., some with scratches, some without), the importance of each channel in the feature map varies. Some channels may specifically respond to scratch features, while others may respond to textured backgrounds. Based on this, this scheme utilizes channel attention branches to dynamically evaluate and disable redundant channels that contribute little to the current image task, performing real-time channel pruning. Specifically, this includes:
[0119] For the C-channel feature map output by the current convolutional block (e.g., C=64), calculate the mean feature gradient μ channel by channel. g,c , which is the average gradient value (calculated using L1 gradient) of all pixels in channel C, reflects the activity or importance of that channel; then based on μ of each channel g,c Calculate the gradient mean μ for all channels g and standard deviation σ g ;
[0120] According to the formula θ=μ g +0.5×σ g Calculate the dynamic threshold, if μ of a certain channel g,c <θ, is considered a redundant channel, meaning it has no effective defect features, such as a channel containing only background information; redundant channels are directly set to zero (without physical deletion, this is a kind of "soft pruning," which does not change the model structure but skips the calculation, avoiding structural changes during inference), and the pruning ratio is preferably controlled at 25% ± 5%; only μ is retained. g,c Identify effective channels with a value ≥ θ, and calculate the channel normalized weights for these effective channels. By enhancing feature sharing across effective channels and ensuring no key features are lost, dynamic model compression is achieved. For each frame of image, the network automatically skips 15% to 35% of channel calculations, further significantly reducing computational load and power consumption with almost no impact on accuracy—something that fixed-structure networks cannot achieve.
[0121] To enable the lightweight student model to achieve performance close to that of the large teacher model, this solution employs knowledge distillation, whereby the student model mimics the behavior and knowledge of the teacher model. In this embodiment, the high-precision knowledge of defect classification provided by the accurate teacher ResNet101, which has a high accuracy rate in classifying cartridge case defects, is used as a supervisory benchmark for the student model's classification ability. The student model learns the teacher model's accurate judgment ability by minimizing the KL divergence loss between its output classification probability and the output probability of ResNet101.
[0122] The efficient teacher model, EfficientNet-B4, provides knowledge on the efficiency of lightweight feature extraction. Its parameter count is only one-third that of ResNet101, resulting in faster inference speeds. This serves as a reference for lightweighting the student model. The student model learns the teacher model's efficient and robust feature representation by minimizing the L2 feature distillation loss between its intermediate layer feature maps and the corresponding layer feature maps of EfficientNet-B4.
[0123] The student model is the ShuffleNetV2+ dynamic attention module network built above, which aims to inherit the high accuracy and high efficiency of both teachers.
[0124] The following is a brief explanation of the distillation training process:
[0125] The server-side hardware used was a GPU (NVIDIA Tesla V100), trained using the TensorFlow framework; the optimizer was the Adam optimizer, with a learning rate of 0.0005; the training epochs were 80, and the batch size was 32; the distillation temperature (t) was initially t=5 (high temperature enhances knowledge transfer robustness and avoids overfitting), and decreased by 0.0375 per epoch (after 80 epochs, t=5-80×0.0375=2).
[0126] Feature distillation loss (feature extraction knowledge transfer): Calculate the L2 loss between the 128-channel feature map output by the 4th convolutional block of the student model and the corresponding layer feature map of EfficientNet-B4, with a weight of 40%, to ensure that the student model inherits the teacher's efficient feature extraction capabilities;
[0127] KL divergence loss (classification knowledge transfer): Calculate the KL divergence between the softening probability distribution output by the student model (softening by temperature T) and the softening probability distribution output by ResNet101, with a weight of 60%, to ensure that the student model inherits the classification accuracy of the teacher.
[0128] The total loss = 0.6 × KL divergence loss + 0.4 × feature distillation loss, and the student model parameters are updated through backpropagation.
[0129] The student model trained by distillation was exported to TensorFlow Lite format, and the model parameters were automatically quantized (from 32-bit floating-point numbers to 16-bit fixed-point numbers), and the model size was compressed to 7.2MB.
[0130] After the above process, the feature extraction network finally outputs a defect feature map of size 128 channels × 104 × 104 (obtained by downsampling the 416 × 416 input image 4 times, 104 = 416 / 4). The response value of the defect area in the feature map is significantly higher than that of the background area. The number of parameters is about 2.8M, which is 56% less than MobileNetV3. The single frame processing time is ≤3.2ms, and the defect feature extraction accuracy is ≥99.2%. It is fully adapted to the high-speed inspection requirements of 160 cartridge cases per minute on the cartridge case production line (160 cartridge cases per minute ≈ 2.67 cartridge cases per second, and a single frame processing time of 3.2ms can meet the requirements).
[0131] S108: Multi-scale segmentation is used to segment the extracted feature map to obtain the defect region, and capsule network is used to classify and identify the defects;
[0132] refer to Figure 5 The feature maps (128 channels) output by the feature extraction network are aggregated by channel average, and then weighted by weights for each group to generate grayscale images to avoid information loss. Local entropy is calculated using multi-scale sliding windows of 3×3, 5×5, and 7×7. The optimal window scale is determined by improving the information entropy gain evaluation. The scale S∈{3,5,7} is used to calculate the information entropy gain G(S)=H(S)-[H(sprev)+H(snext)] / 2. The boundary scale is only compared with the nearest neighbor (sprev=5 when S=3; sprev=3 and snext=7 when S=5). When S=7, snext=5), the segmentation threshold is calculated by weighted fusion of the maximum inter-class variance method and the local entropy value according to the formula T=0.7×Totsu+0.3×Tentropy, and the defect region is segmented. The geometric topological features and depth texture features of the defect region are extracted and input into a lightweight hybrid classifier based on capsule network. The capsule network has 3 layers (64D input layer, 32×8D primary capsule layer, and 6×16D digital capsule layer), and directly outputs the defect classification results, realizing the fine classification of 6 types of defects such as scratches, cracks, dents, blemishes, ring marks, and wrinkles.
[0133] In this embodiment, the core objective of multi-scale segmentation is to accurately segment the defect region from the 128-channel defect feature map. This includes key steps such as feature map to grayscale conversion, multi-scale entropy calculation, optimal scale selection, threshold fusion, and defect segmentation. The specific process is as follows:
[0134] 1) Convert the 128-channel feature map to a grayscale image;
[0135] The 128-channel feature map is averaged by channel dimension. Specifically, the 128 channels can be divided into 3 groups. For example, channels 1-42 are the shallow feature group, corresponding to defect edges; channels 43-86 are the medium feature group, corresponding to defect texture; and channels 87-128 are the deep feature group, corresponding to defect semantics. The pixel values of all channels in each group are averaged to obtain 3 grouped average feature maps, which are denoted as F1, F2, and F3 respectively. For example, the shallow feature group F1(i,j) = (1 / 42) × Σ(pixel value of channels 1-42 at (i,j)).
[0136] The importance of feature layers at different depths varies. Mid-layer features are the most crucial and therefore have the highest weight; shallow features assist in localization and have the next highest weight; deep features contribute little to segmentation and have the lowest weight. Specifically, the weighted sum of the average feature maps of the three groups is calculated using weights [0.3, 0.6, 0.1] to generate the final grayscale image (Grey). The formula is as follows:
[0137] Grey(i,j)=0.3×F1(i,j)+0.6×F2(i,j)+0.1×F3(i,j)
[0138] The pixel values of the grayscale image are normalized to the range of 0-255 to avoid the impact of brightness differences between different batches of feature maps on segmentation. The formula is as follows:
[0139]
[0140] In the formula, G max G min These are the maximum and minimum pixel values of the grayscale image Grey, respectively.
[0141] 2) Calculate multi-scale local entropy;
[0142] Local entropy is calculated using windows of different sizes to accommodate defects of different sizes: 3×3 windows for small cracks, 5×5 windows for medium cracks, and 7×7 windows for large scratches. All three types of windows are centered on the current pixel, and edge pixels are filled with mirror images to avoid loss of edge information. Due to the abrupt change in grayscale, the entropy value of the defect area is significantly higher than that of the uniform background area, providing a basis for differentiation in subsequent segmentation.
[0143] The sliding step size is set to 4 pixels, meaning that the local entropy is calculated once every 4 pixels the window moves horizontally / vertically; for the normalized grayscale image G... norm The local entropy H(S) within a certain window (where S is the window size, S∈{3,5,7}) is calculated according to the definition of information entropy:
[0144]
[0145] In the formula, p k The proportion of pixels with gray level k within the window to the total number of pixels in the window; if p k =0, define p k ×log2(p k = 0 to avoid the logarithm being meaningless. Output three local entropy maps H(3), H(5), and H(7) at different scales (3×3, 5×5, 7×7).
[0146] Optionally, the window entropy values at the three scales can be calculated in parallel using the CUDA cores of the NVIDIA Jetson Xavier NX, ensuring that the entropy calculation time for a single scale is <0.6ms and the total time for the three scales is <2ms.
[0147] 3) Determine the optimal segmentation scale;
[0148] For each pixel in the image, select the window scale that best distinguishes defects from the background, i.e., the optimal segmentation scale. At this scale, the local entropy has the highest discriminative power, avoiding segmentation bias of defects of different sizes by a single scale. For example, a small window may miss large defects, while a large window may blur small defects.
[0149] For each pixel, calculate its entropy gain G(S) at the three scales:
[0150] G(S)=H(S)-[H(sprev)+H(snext)] / 2
[0151] In the formula, the information entropy gain G(S) represents the difference between the entropy value H(S) at the current scale and the average entropy value of the two adjacent scales. The larger G(s) is, the more significant the difference between the entropy value at the current scale and other scales, and the stronger the ability to distinguish defects in the region where the pixel is located.
[0152] When S = 3 (minimum scale), only compare with S = 5, the formula simplifies to G(3) = H(3) - H(5) ("sprev = 5 when S = 3");
[0153] When S = 5 (intermediate scale), compared with S = 3 and S = 7, the original formula G(5) = H(5) - [H(3) + H(7)] / 2 is used for calculation;
[0154] When S = 7 (maximum scale), the formula is simplified to G(7) = H(7) - H(5) ("snext = 5 when S = 7") when compared only with S = 5.
[0155] For each pixel, the scale with the largest G(s) is selected as the optimal segmentation scale for that pixel.
[0156] 4) Calculate the segmentation threshold;
[0157] This embodiment generates a segmentation threshold that takes into account both global background and local defects by combining the global optimal threshold and the local entropy threshold, thus avoiding the segmentation failure of a single threshold in scenarios with lighting fluctuations and local noise.
[0158] Specifically, the Otsu's method is used to normalize the grayscale image G. norm The globally optimal threshold Totsu, which best distinguishes the foreground and background of an image, is calculated. By iterating through all possible gray values (0-255), the gray value that maximizes the inter-class variance between the defect and the background is found and used as the globally optimal threshold Totsu.
[0159] For each pixel, calculate the local threshold Tentropy based on its local entropy H(S) at its optimal segmentation scale. Calculate H(S) for all pixels and take the median of H(S) as the local entropy threshold Tentropy.
[0160] Fuse Totsu and Tentropy according to the given weights, and calculate the segmentation threshold T. The formula is as follows:
[0161] T = 0.7×Totsu + 0.3×Tentropy
[0162] In the formula, the global optimal threshold Totsu can stably segment most regions, and the local entropy threshold Tentropy can correct local special regions (such as edge-blurred defects). The combination of the two enhances the segmentation robustness. Based on the segmentation threshold, the feature extraction network can segment the corresponding defect regions.
[0163] 5) Segment the defect regions;
[0164] For the normalized grayscale image G norm Perform binary processing according to the segmentation threshold T. If G norm (i, j) ≥ T, it is determined as a defect pixel and assigned a value of 255 (white); if G norm (i, j) < T, it is determined as a background pixel and assigned a value of 0 (black); output the binary image B; and remove the connected regions with an area < 5 pixels (the specific connected region threshold can be flexibly set), and retain the connected regions with an area ≥ 5 pixels, which are the effective defect regions; Since the feature map (52×52) is obtained by downsampling the original image (416×416) by 8 times (416 / 52 = 8), the pixel coordinates of the segmented defect regions need to be mapped back to the original image coordinates to facilitate the subsequent classifier to extract features for accurate positioning. The mapping formula is:
[0165] (x orig, y orig ) = (x feat ×8, y feat ×8)
[0166] In the formula, (x feat , y feat ) are the defect pixel coordinates in the feature map, and (x orig , y orig ) are the corresponding coordinates in the original image.
[0167] 6) Identify the defect types of the defect regions based on the lightweight hybrid classifier of the capsule network;
[0168] Refer to Figure 6 , for the input defect regions, first perform hybrid feature extraction on them, including geometric topology features and depth texture features, and splice and fuse the extracted features, and then input them into the capsule network to output the defect classification results.
[0169] Geometric topological features include morphological features (such as area, perimeter, aspect ratio, minimum bounding rectangle), contour features (concavity / convexity, Euler number), and moment features (Hu invariant moments); depth texture features are obtained by global average pooling of defect region features; the two types of features are concatenated and normalized to form hybrid features; capsule networks are used to replace traditional fully connected layers to better maintain the spatial hierarchy of features.
[0170] The capsule network consists of an input layer (64D) that converts mixed features into the output of 64 neurons; a primary capsule layer (32×8D) that converts scalars into vectors, consisting of 32 capsules, each an 8-dimensional vector; and a digital capsule layer (6×16D) consisting of 6 capsules, each a 16-dimensional vector, corresponding to 6 types of defects. By calculating the magnitude of the output vector of each digital capsule, the Squashing function is used to compress the magnitude to between 0 and 1, outputting a 6-dimensional probability vector, and the maximum value is taken as the classification result.
[0171] refer to Figure 7 In an optional embodiment of this application, the light intensity (ΔL) and temperature (ΔT) of the production environment can be collected by industrial sensors to establish a lightweight MLP model and dynamically adjust the classification confidence threshold Th. An automatic labeling channel for defective samples is established, and samples with a detection confidence of <0.85 are automatically screened weekly. Semi-supervised labeling is achieved through pseudo-label generation and manual review. When the number of new samples reaches 10% to 15% of the current total number of samples, local incremental training (only updating the classifier layer) is triggered, with an incremental training time of ≤2 hours. Environmental parameters and training results are synchronously fed back to the entire process, dynamically adjusting and optimizing the fusion weight parameters in step S104, the channel pruning ratio in step S106, and the segmentation threshold in step S108. This achieves adaptive adjustment throughout the entire process, rather than just optimizing the classifier, ensuring a stable improvement in overall detection performance.
[0172] refer to Figure 8 The MLP model is a typical regression model, whose goal is to establish a nonlinear mapping function Th = f from environmental parameters [ΔL, ΔT] to the optimal classification confidence threshold Th. MLP (ΔL,ΔT).
[0173] Illuminance (ΔL) was collected by an SL2591 sensor, ranging from 0 to 10000 lux with an accuracy of ±50 lux. Temperature (ΔT) was collected by an SHT30 sensor, ranging from -40℃ to 125℃ with an accuracy of ±0.5℃. The collected environmental parameters were first preprocessed, including linearly normalizing the raw sensor data to the [0,1] interval to eliminate dimensional differences.
[0174] ΔLnorm=ΔL / 10000; ΔLnorm represents the normalized light intensity;
[0175] ΔTnorm = (ΔT + 40) / 165 (maps the range [-40, 125] to [0, 1]); ΔTnorm represents the normalized ambient temperature.
[0176] The MLP model's input layer consists of two neurons, receiving normalized ΔLnorm and ΔTnorm respectively. The hidden layer consists of one layer with eight neurons, which linearly transforms the input and then activates it using the ReLU (Rectified Linear Unit) function. The output layer consists of one neuron, which linearly transforms the output of the hidden layer and then activates it using the Sigmoid function. The Sigmoid function converts the output value Th... raw Compressed to the range (0,1), then scaled and mapped to the final threshold range [0.7,0.9]: Th = 0.7 + Th raw *0.2.
[0177] During the training phase, historical data (environmental parameters ΔL + ΔT + optimal Th + detection accuracy) are used for training. The goal is to ensure that when Th fluctuates by ±30% in the environment, the detection accuracy fluctuation is <0.3%. After training, the main control device inputs the latest ΔL and ΔT every 5 minutes, and the MLP model outputs Th in real time to directly update the judgment threshold of the hybrid classifier. For example, when the strong light ΔL = 8000 lux, Th is increased from 0.8 to 0.85 to reduce false detections caused by reflection.
[0178] In this embodiment, by continuously accumulating low-confidence detection results and reducing manual costs through semi-supervised annotation, the problem of long model update cycles and difficulty in quickly responding to new defects is solved.
[0179] Specifically, samples with a confidence level <0.85 are automatically screened weekly, including two categories: "suspected defects not identified" and "non-defects misidentified as defects." Semi-supervised labeling is achieved through pseudo-label generation and manual review. Pseudo-label generation involves directly using the current best model to predict the selected samples, and using the prediction result (e.g., "crack, confidence level 0.82") as the "pseudo-label." Manual review only involves manually verifying samples with a pseudo-label confidence level <0.8 (accounting for about 10% of the total) and correcting mislabeling (e.g., changing the label "stain misidentified as scratch" to "background"). The labeled samples are then stored in the defect sample database for subsequent incremental training.
[0180] When the number of newly added samples reaches the update requirement, for example, when it reaches 10% to 15% of the total number of samples in the current sample library (e.g., if the sample library currently has 10,000 samples, adding 1,000 to 1,500 samples triggers local incremental training. Based on the newly labeled samples, such as 1,000-1,500 samples, a number of samples are randomly selected from the sample library, such as 500 samples, to avoid the model forgetting old defective features; only the digit capsule layer of the hybrid classifier (i.e., the classifier layer) is updated to avoid the excessive time consumption of full training and to achieve rapid evolution with weekly updates; and the feature extraction network is frozen to avoid the degradation of feature extraction capabilities; at the same time, the Adam optimizer is used (the learning rate is set to 0.0001, which is lower than full training to avoid overfitting), the batch size is set to 16, and the training epochs are set to 20; in addition, TensorRT quantization can be used to accelerate the training, converting the model parameters from 32-bit floating-point numbers to 16-bit fixed-point numbers, compressing the training time to within 2 hours.
[0181] After training is complete, the accuracy of the new model on the test set (1000 labeled samples that were not used in training) is calculated. If the accuracy is improved compared to the original model, the production line model is automatically replaced; if it is not improved, the update is abandoned and the original model is retained to avoid performance degradation.
[0182] Environmental parameters and training results are synchronously fed back to the entire process, dynamically adjusting and optimizing relevant parameters throughout the process, for example:
[0183] The fusion weights (w1 = visible light weight, w2 = near-infrared weight) are adjusted according to the illumination intensity ΔL. When ΔL > 5000 lux (strong light), w1 is reduced (from 0.4 + 0.1 × T1 to 0.3 + 0.1 × T1) and w2 is increased (from 0.3 + 0.1 × T2 to 0.4 + 0.1 × T2) to avoid reflection interference in the visible light image. When ΔL < 1000 lux (weak light), w1 is increased and w2 is reduced to enhance visible light texture features and reduce noise interference.
[0184] Regarding the channel pruning ratio, the channel pruning ratio is dynamically optimized based on the PID controller. If the model accuracy improvement is insufficient after incremental training, the pruning ratio is appropriately reduced, such as from 20% to 15%, to retain more feature channels and improve defect capture capability. If the detection speed decreases, the pruning ratio is appropriately increased, such as from 20% to 25%, to reduce computing power consumption and ensure high-speed detection.
[0185] For example, the segmentation threshold T can be adjusted based on the temperature ΔT. When ΔT > 30℃ (high temperature, oil stains and reflections are likely to appear on the surface of the cartridge case), T can be increased (e.g., from 120 to 130) to reduce the misjudgment of oil stains as defects. When ΔT < 10℃ (low temperature, grayscale contrast of the cartridge case surface is reduced), T can be decreased (e.g., from 120 to 110) to avoid missing low-contrast cracks.
[0186] Based on the technical solutions provided in the embodiments of this application, at least the following beneficial effects are achieved:
[0187] 1. Enhanced Defect Detection Capability through Multimodal Approach: Normalized weight fusion and polarization mode improve the detection rate of latent defects to 99.5% and reduce the false negative rate to 0.5%, comprehensively solving the problem of incomplete capture of complex defect features.
[0188] 2. Dynamic lightweight resource optimization: By using gradient graph spatial attention and adaptive pruning, the number of parameters is reduced by 56% compared to MobileNetV3, and the single-frame detection time is reduced to 8ms, meeting the high-speed detection requirements of the production line.
[0189] 3. Improved intelligent classification accuracy: The 6×16D capsule network achieves 99.5% accuracy, with accuracy fluctuation of <0.3% when illumination fluctuates by ±30%, solving the problem of poor environmental adaptability.
[0190] 4. Breakthrough in closed-loop evolution efficiency: Full-process feedback and incremental training shorten the model update cycle to 1 week and improve the response speed of new defect identification by 70%, meeting the dynamic adjustment needs of flexible production.
[0191] Please refer to Table 1 below for details:
[0192] Table 1 Comparison of Technical Effects and Experimental Data
[0193]
[0194]
[0195] Based on the above method embodiments, this embodiment also provides a lightweight detection system for surface defects in cartridge cases, which can be used to implement the steps of the above method.
[0196] refer to Figure 9 The lightweight defect detection system for cartridge cases includes:
[0197] The acquisition module 91 is used to acquire the visible light image, near-infrared image and polarization image of the shell to be detected;
[0198] The fusion preprocessing module 92 is used to generate an enhanced image using a dynamic weight fusion algorithm;
[0199] Feature extraction module 93 is used to dynamically extract features from the enhanced image using a feature extraction network;
[0200] The multi-scale segmentation module 94 is used to segment the extracted feature map using multi-scale segmentation to obtain the defect region;
[0201] The classification module 95 is used to identify the defect type corresponding to the defect region using a lightweight hybrid classifier based on capsule network and output the identification result.
[0202] Various variations and specific examples of the methods provided in the above embodiments are also applicable to the system of this embodiment. Through the foregoing detailed description of the methods, those skilled in the art can clearly understand the implementation method of the system in this embodiment. For the sake of brevity, they will not be described in detail here.
[0203] To better execute the above methods, embodiments of this application also provide a computer device, such as... Figure 10 As shown, the computer device includes a processor, a memory, and a communication bus for enabling communication between the processor and the memory.
[0204] Computer devices can take many forms, including mobile phones, tablets, handheld computers, laptops, and desktop computers.
[0205] The memory can be used to store instructions, programs, code, code sets, or instruction sets. The memory may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for at least one function, and instructions for implementing the methods provided in the above embodiments; the data storage area may store data involved in the methods provided in the above embodiments.
[0206] Optionally, the memory may be a read-only memory (ROM), random access memory (RAM), electrically erasable programmable read-only memory (EEPROM), optical disc (including compact disc read-only memory (CD-ROM), compressed optical disc, laser disc, digital versatile optical disc, Blu-ray disc, etc.), magnetic disk storage medium, or other magnetic storage device, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited to these. The memory exists independently and is connected to the processor via a communication bus, or the memory is integrated with the processor.
[0207] A processor may include one or more processing cores. The processor executes instructions, programs, code sets, or instruction sets stored in memory, and calls data stored in memory to perform various functions and process data as described in this application. The processor may be at least one of the following: Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), Central Processing Unit (CPU), controller, microcontroller, and microprocessor. It is understood that, for different devices, the electronic devices used to implement the above-described processor functions may also be other types, and the embodiments of this application do not specifically limit this.
[0208] The communication bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0209] In an alternative embodiment, the computer device may further include a communication interface (not shown) for communication with other devices.
[0210] This application provides a computer-readable storage medium, including, for example, various media capable of storing program code such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. This computer-readable storage medium stores a computer program that can be loaded by a processor and execute the methods of the above embodiments.
[0211] This application also provides a computer program product comprising a computer program tangibly embodied on a readable medium thereof, the computer program containing program code for performing any of the methods described in any of the embodiments of this application, the computer program being downloadable and installable over a network, and / or installed from a removable medium (such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc.).
[0212] The above description of the embodiments is only used to provide a detailed introduction to the technical solutions of this application. However, the description of the above embodiments is only for the purpose of helping to understand the methods and core ideas of this application, and should not be construed as a limitation of this application. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the protection scope of this application.
Claims
1. A lightweight detection method for surface defects in cartridge cases, characterized in that, The method includes: The visible light image, near-infrared image and polarization image of the shell to be detected are acquired, and an enhanced image is generated by a dynamic weight fusion algorithm. Dynamic feature extraction of enhanced images is performed using a feature extraction network. Multi-scale segmentation is used to segment the extracted feature map to obtain defect regions, and a lightweight hybrid classifier based on capsule network is used to identify the defect type corresponding to the defect region, and the identification result is output.
2. The method as described in claim 1, characterized in that, The dynamic weight fusion algorithm includes: Calculate the fusion weights corresponding to the visible light image, the near-infrared image, and the polarization image respectively; The corresponding fusion weights are normalized so that the normalized fusion weight values are limited to the range of (0,1) and the sum of the normalized fusion weights is 1. Based on the normalized fusion weights, the visible light image, the near-infrared image, and the polarization image are weighted and summed to obtain the enhanced image.
3. The method as described in claim 2, characterized in that, The calculation of the fusion weights corresponding to the visible light image, the near-infrared image, and the polarization image includes: The fusion weight w1 corresponding to the visible light image is calculated based on the texture sharpness index T1, and the calculation formula is: w1=0.4+0.1×T1, where the texture sharpness index T1 is the standard deviation of the gradient magnitude corresponding to the visible light image; The fusion weight w2 corresponding to the near-infrared image is calculated based on the infrared response intensity T2, and the calculation formula is: w2=0.3+0.1×T2, where T2 is the average gray value corresponding to the near-infrared image; The fusion weight w3 corresponding to the polarization image is calculated based on the polarization difference degree T3, and the calculation formula is: w3=0.3+0.1×T3; where T3 is the multi-angle intensity variance corresponding to the polarization image.
4. The method as described in claim 1, characterized in that, The feature extraction network is based on ShuffleNetV2 architecture, removing the 1×1 convolutional layer from the native ShuffleNetV2 network. The feature extraction network includes four convolutional blocks, each of which includes grouped convolution, channel shuffling, and downsampling. A dynamic attention mechanism module is embedded between the convolutional blocks, with the output of each convolutional block as the embedding point. The dynamic attention mechanism module includes a spatial attention branch and a channel attention branch. The spatial attention branch is used to generate spatial weights, and the channel attention branch is used for channel pruning.
5. The method as described in claim 4, characterized in that, The channel attention branch is used to calculate the gradient mean μ of all channels. g and standard deviation σ g According to the formula θ=μ g +0.5×σ g Calculate the dynamic threshold, if the μ of a certain channel g,c If the value is less than θ, it is considered a redundant channel. Redundant channels are set to zero, and only μ is retained. g,c Identify effective channels with a value ≥ θ, and calculate the channel normalized weights for these effective channels. To enhance the sharing of features in effective channels.
6. The method as described in claim 4, characterized in that, The method further includes: optimizing network performance using a dual-teacher knowledge distillation strategy, with ResNet101 (precision teacher) and EfficientNet-B4 (efficiency teacher) as a joint teacher model; the feature extraction network serves as the student model, achieving knowledge transfer by minimizing KL divergence loss and feature distillation loss, with the distillation temperature parameter linearly decreasing from 5 to 2, decreasing by 0.0375 per training round.
7. The method as described in claim 1, characterized in that, The defect region is obtained by segmenting the extracted feature map using multi-scale segmentation, including: Convert the extracted feature map into a grayscale image; Calculate the local entropy H(S) for different window sizes for a grayscale image: In the formula, p k This represents the proportion of pixels with gray level k within the window to the total number of pixels in the window. Calculate the information entropy gain G(S) based on the local entropy H(S) corresponding to different window sizes: G(S)=H(S)-[H(sprev)+H(snext)] / 2 The scale S∈{3,5,7}; When S = 3, the formula for calculating the information entropy gain G(S) is G(3) = H(3) - H(5); When S = 5, the formula for calculating the information entropy gain G(S) is G(5) = H(5) - [H(3) + H(7)] / 2; When S = 7, the formula for calculating the information entropy gain G(S) is G(7) = H(7) - H(5); For each pixel, the window with the largest G(s) size is selected as the optimal segmentation scale for that pixel; The local threshold Tentropy is calculated based on the local entropy H(S) under the optimal segmentation scale. Combining the globally optimal threshold Totsu, the segmentation threshold T is calculated using the following formula: T = 0.7 × Totsu + 0.3 × Tentropy The grayscale image is binarized based on the segmentation threshold T. If the grayscale value is greater than T, it is determined to be a defective pixel. The connected region whose area reaches the set area threshold is retained as the effective defect region.
8. The method as described in claim 1, characterized in that, The method of using a lightweight hybrid classifier based on capsule networks to identify the defect type corresponding to the defect region includes: Geometric topological features and depth texture features are extracted from the input defect region. The extracted geometric topological features and depth texture features are then concatenated and fused to form a hybrid feature. This hybrid feature is then input into a capsule network and outputs the corresponding defect type.
9. The method as described in claim 8, characterized in that, The capsule network includes: The input layer is used to convert the mixed features into an output of 64 neurons. The primary capsule layer, used to convert scalars into vectors, consists of 32 capsules, each of which is an 8-dimensional vector. The digital capsule layer consists of 6 capsules, each of which is a 16-dimensional vector corresponding to 6 defect types. By calculating the magnitude of the output vector of each digital capsule, the Squashing function is used to compress the magnitude to between 0 and 1, outputting a 6-dimensional probability vector, and taking the maximum value as the recognition result.
10. A lightweight detection system for surface defects in cartridge cases, characterized in that, include: The acquisition module is used to acquire the visible light image, near-infrared image, and polarization image of the shell to be detected; The fusion preprocessing module is used to generate enhanced images using a dynamic weight fusion algorithm; The feature extraction module is used to dynamically extract features from the enhanced image using a feature extraction network; The multi-scale segmentation module is used to segment the extracted feature map using multi-scale segmentation to obtain the defect region; The classification module is used to identify the defect type corresponding to the defect region using a lightweight hybrid classifier based on capsule networks, and output the identification results.
Citation Information
Cited By
Radome surface defect automatic detection system
CN121805261A
An automatic detection system for surface defects of a radome
CN121805261B
Insulator defect detection method and device, storage medium and computer equipment
CN121921693A
Insulator defect detection method and device, storage medium and computer device
CN121921693B
Shielding film defect detection method and system
CN122115453A