A deep learning-based casting internal defect detection method
By incorporating the CS-Block module with channel and spatial attention mechanisms and a multi-scale feature fusion module into the ResNet-50 network, combined with an improved K-means clustering algorithm, the problem of defect detection in X-ray images of aluminum alloy castings under noise and complex backgrounds was solved, achieving efficient and high-precision multi-scale defect detection.
Patent Information
- Application Number
- CN202310350619.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-04
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-04-04
AI Technical Summary
Existing technologies often encounter problems with noise and complex defect backgrounds in X-ray images of aluminum alloy castings. Traditional detection algorithms are inefficient and have a high false detection rate, making it difficult to achieve high-precision automated detection of internal defects in aluminum alloy castings.
We employ a ResNet-50 residual network combined with a channel and spatial attention mechanism in the CS-Block module, and incorporate a multi-scale feature fusion module and an improved K-means clustering algorithm to improve the accuracy and efficiency of defect detection through deep learning methods.
It achieves high-precision multi-scale defect detection in complex backgrounds and noisy environments, especially improving the detection accuracy of small-scale defects, with a detection time of only 0.024s and an average accuracy of 96.52%.
Smart Images

Figure CN116664479B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of intelligent detection technology for internal defects in automotive die castings, and relates to a deep learning-based method for detecting internal defects in castings. Background Technology
[0002] With the development of lightweight technology, aluminum alloy die castings have been widely used in the automotive, aerospace, and other fields. During the die casting process, defects such as bubbles, shrinkage cavities, and cracks are unavoidable due to improper operation and poor mold quality. For these internal defects in aluminum alloy castings, non-destructive testing is typically performed using X-ray imaging. However, in the production process, these defects are mainly detected manually by adjusting parameters such as brightness and contrast of X-ray images, which is not only inefficient but also has a high false detection rate. Therefore, researching intelligent visual inspection algorithms based on digital radiography (DR) is of great significance.
[0003] Intelligent visual inspection algorithms based on radiography (DR) are typically used to construct object detection tasks. The development of object detection algorithms can be divided into two stages: traditional detection algorithms based on manually extracted features and object detection algorithms based on deep learning. Due to the high noise levels in X-ray images of aluminum alloy castings and the complexity of defects and their backgrounds, traditional detection algorithms cannot achieve the required accuracy for automated inspection. In contrast, deep learning-based detection algorithms exhibit better performance in complex environments compared to traditional methods. They also demonstrate high accuracy in detecting multi-scale defects, especially small-scale defects that are difficult to detect, while offering millisecond-level detection speeds. This allows for effective real-time detection of internal defects in aluminum alloy castings in complex scenarios. Summary of the Invention
[0004] This invention primarily addresses the challenge of improving the detection performance of multi-scale defects in X-ray images of aluminum alloy castings, where noise levels and complex defect backgrounds are prevalent. A deep learning-based defect detection method for X-ray images of aluminum alloy castings is proposed. The classification network employs a ResNet-50 residual network, incorporating a hybrid attention module (CS-Block) that combines channel and spatial attention mechanisms. This further filters feature information from different channels and spatial dimensions in the feature map, suppressing irrelevant information and increasing the weight of the defect location and effective feature information within the feature map, thus reducing interference from background, noise, and other information. To fully utilize the extracted features and further improve the model's detection accuracy for multi-scale defects, especially small-scale defects, a multi-scale feature integration module (MFIM) using a feature pyramid network structure is added after the CS-Block module. This module uses lateral connections to fuse shallow features with upsampled deep semantic information from top to bottom, constructing a multi-scale fused feature map that integrates semantic information at various levels and defect location information. An improved K-means clustering algorithm was used to redesign the size and dimensions of the anchor points, further improving the model's performance in detecting multi-scale defects.
[0005] To achieve the above objectives, the technical solution of the present invention is as follows:
[0006] A deep learning-based method for detecting internal defects in castings includes the following steps:
[0007] Step 1: Acquire images using an internal defect detection system for castings;
[0008] The aforementioned casting internal defect detection system includes a high-frequency X-ray machine, a control console, an industrial-grade digital flat panel detector, a computer image processing system, a mechanical transmission control system, a lead-lined protective system, and other auxiliary components. The system detects bubbles, porosity, shrinkage cavities, cracks, etc., with a detection cycle of 1.2–15 frames. The smallest resolvable deep hole is 0.3–0.4 mm. The X-ray machine's maximum penetration capability for aluminum alloys during real-time imaging can reach 80 mm. During inspection, the workpiece is placed on a work platform between the X-ray source and the industrial-grade digital flat panel detector. The control console uses a mechanical joystick to control the mechanical transmission control system (PLC, AC motor), such as controlling the left and right movement and ±360° rotation of the work platform, as well as the vertical movement and ±30° oscillation of the X-ray source and digital flat panel. The industrial control computer on the control console communicates point-to-point with the X-ray source via an RS-232 interface to control the X-ray intensity and communicates with the digital flat panel detector via gigabit Ethernet to receive X-ray imaging information of the workpiece under test. Then, a computer image processing system is used to complete functions such as image acquisition, image storage, image processing, image evaluation, and image printing. In addition, the industrial control computer is equipped with a DVD burner, which can archive the acquired image information and inspection results onto CDs at any time to prevent data loss. The casting internal defect detection system collected a total of 14,640 images of internal defects in aluminum alloy castings, including components such as automotive radiator panels, chain covers, oil pans, crankcases, clutch housings, and transmission housings. The original defect images in the dataset had a resolution of 1140×1192 pixels, which were adjusted to 512×512 for network input. Specific defects included porosity, shrinkage cavities, looseness, and cracks.
[0009] Step 2: Dataset creation and data augmentation;
[0010] The original dataset consists of the original images and files labeled with defect categories and locations, in PascalVOC format. To address the imbalance in the number of samples with different defects, data augmentation techniques such as rotation, horizontal flipping, random brightness adjustment, and HSV adjustment are used. The augmented dataset is then randomly divided into training, validation, and test sets in a ratio of 8:1:1.
[0011] Step 3: Model building, training, and testing;
[0012] The backbone network of the defect detection algorithm in this invention adopts a ResNet-50 residual network. Using a deeper network allows for the acquisition of deeper semantic features from defect images. Furthermore, the residual block structure used in the ResNet network overcomes the problem that learning efficiency and accuracy cannot be effectively improved with increasing network depth, achieving higher accuracy compared to traditional classification networks such as VGG. To reduce interference from X-ray image noise and complex backgrounds, a CS-Block attention module, which combines channel attention and spatial attention mechanisms, is added after Conv3_x, Conv4_x, and Conv5_x. This module further filters feature information from different channels and in space within the feature map to suppress irrelevant information, thereby increasing the weight of the defect location region and effective feature information in the feature map and reducing the interference of background, noise, and other information on defect detection.
[0013] The CS-Block module consists of a channel attention module (C-Block) and a spatial attention module (S-Block). It adds spatial dimension attention after the channel attention mechanism, improving the model's attention to the spatial location of features. Based on the characteristics of the feature maps generated by the network at different depths, the CS-Block-A structure, which uses max pooling to calculate attention, is used in shallow layers (primarily texture features) and intermediate layers (transitional features). In deeper feature maps with richer semantic information, the CS-Block-B structure, which combines max pooling and mean pooling, is used to calculate attention.
[0014] To more fully utilize the extracted features and further improve the model's detection accuracy for multi-scale defects, especially small-scale defects, a multi-scale feature fusion module using a feature pyramid network structure is added after the CS-Block module. This module employs lateral connections to fuse shallow features with upsampled deep semantic information sequentially from top to bottom, constructing a multi-scale fused feature map that incorporates semantic information at all levels and defect location information. A Conv3×3 convolutional layer is then used to extract features from the generated feature map again to eliminate aliasing effects that may arise from the upsampling process. Finally, the multi-scale fused feature map is input into the classification and regression modules.
[0015] In the classification and regression stages, the M values obtained after convolution and fusion by Conv3×3 convolutional layers are obtained on the P3, P4, and P5 prediction feature layers. p3 M p4 M p5 Three multi-scale feature maps. Among them, M p3 The corresponding shallow texture features of the image, M p4 Corresponding to the transition features of the intermediate layer, Mp5 This corresponds to deeper semantic features in the image. In M p5 Based on this, M is obtained by sequentially passing it through a Conv3×3 convolutional layer with stride=2. p6 M p7 This corresponds to the deep semantic features of the image. Finally, defect detection is performed on five predicted feature layers: P3, P4, P5, P6, and P7. The reason for starting small-scale defect detection from P3 is that the feature maps generated by Conv1 and Conv2_x are quite large, with a size at least tens of times larger than small-scale defects. Generating preselected boxes would consume a lot of computational resources. Starting small-scale defect detection from P3 reduces resource waste and improves detection efficiency.
[0016] The defect detection algorithm's predictor consists of two parts: a class subnet and a box subnet. The class subnet is responsible for predicting the target category, while the box subnet is responsible for predicting the target bounding box regression parameters. Both subnets consist of four Conv3×3 convolutional layers with stride=1 and channel=256, and one Conv3×3 convolutional layer with stride=1 and channel=36.
[0017] Step 4: Improve K-means clustering operations;
[0018] During prediction, the accuracy of defect detection is measured for each anchor point based on the size of its ground truth bounding box and its intersection over union (IoU). To obtain anchor point sizes suitable for the X-ray image dataset and improve the model's accuracy in detecting defects at different scales in the dataset, statistical analysis was performed on the ground truth boundaries of all defects in the dataset using an improved K-means clustering algorithm. When calculating the similarity between samples and clusters, 1-IoU was used as the metric to replace the Euclidean distance in the original K-means algorithm, thus resolving the error caused by the anchor box size when calculating Euclidean distance and improving the accuracy of the clustering results. The main calculation process is as follows:
[0019] (1) Define the number k that can be clustered into the same category;
[0020] (2) Randomly select k samples from all samples as the initial centers of the cluster;
[0021] (3) Using 1-IoU as the similarity metric between a sample and its cluster, the distance of the Ground Truth of each sample from the center of each cluster is calculated. The calculation formula is as follows:
[0022] ①Based on the image width w Image and high h Image Width of normalized Ground Truth w Ground Truth and high h Ground Truth ,Right now:
[0023]
[0024]
[0025] ②Assuming there are two Ground Truths: a and b, the IoU calculation formula for a and b is:
[0026]
[0027] In the formula: intersection(a,b) represents the area of the intersection of a and b, and union(a,b) represents the area of the union of a and b. The calculation formula is as follows:
[0028] intersection(a,b)=min(w a ,w b )×min(h a ,h b (4)
[0029] union(a,b)=w a ×h a +w b ×h b (5)
[0030] In the formula: w a h represents the width of a. a w represents the height of a. b h represents the width of b. b This represents the height of b.
[0031] (4) Compare the distance (1-IoU value) from each sample to each cluster center and assign it to the cluster with the smallest value;
[0032] (5) Calculate the mean of the width and height of all Ground Truths in each cluster as the new cluster center;
[0033] (6) Repeat steps 3 to 5 until the cluster center no longer changes, or the change value reaches the termination condition;
[0034] The effects and benefits of this invention are:
[0035] The algorithm proposed in this invention improves the defect detection performance of the defect detection model in complex backgrounds and noisy environments by incorporating the CS-Block attention module, which combines channel attention and spatial attention mechanisms. Following the CS-Block module, a multi-scale feature fusion module using a feature pyramid network structure is added. This module fuses shallow features with upsampled deep semantic information from top to bottom using lateral connections, constructing a multi-scale fused feature map that combines semantic information at various levels with defect location information. This improves the model's detection accuracy for multi-scale defects, especially small-scale defects. Furthermore, by redesigning the anchor points using an improved K-means clustering algorithm, 1-IoU is used as the metric for calculating the similarity between samples and clusters, replacing the Euclidean distance in the original K-means algorithm. This resolves the error caused by the anchor frame size when calculating Euclidean distance, improving the accuracy of clustering results and further enhancing the model's detection accuracy for multi-scale defects. Experiments show that the algorithm achieves a mean average precision (mAP) of 96.52% across all categories when the Intersection over Union (IoU) ratio is 0.5, and the detection time is only 0.024s. It can effectively achieve high-precision real-time detection of aluminum alloy castings in scenarios with high noise and complex defect backgrounds in X-ray images. Attached Figure Description
[0036] Figure 1 This is a diagram of the defect detection algorithm structure.
[0037] Figure 2 Diagram of an internal defect detection system for castings;
[0038] Figure 3 Here is a diagram of the CS-Block attention module structure;
[0039] Figure 4 This is a structural diagram of the multi-scale feature fusion module. Detailed Implementation
[0040] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings and technical solutions.
[0041] The structure diagram of the deep learning-based casting internal defect detection algorithm provided in this embodiment of the invention is shown below. Figure 1The classification network employs a ResNet-50 residual network, with a hybrid attention module (CS-Block) incorporating channel and spatial attention mechanisms. This module further filters feature information from different channels and spatial dimensions in the feature map to suppress irrelevant information, thereby increasing the weight of the defect location and effective feature information in the feature map and reducing interference from background, noise, and other information. To more fully utilize the extracted features and further improve the model's detection accuracy for multi-scale defects, especially small-scale defects, a multi-scale feature integration module (MFIM) using a feature pyramid network structure is added after the CS-Block module. This module uses lateral connections to fuse shallow features with upsampled deep semantic information from top to bottom, constructing a multi-scale fused feature map that combines semantic information at all levels with defect location information. An improved K-means clustering algorithm is used to redesign the anchor point size, further enhancing the model's performance in detecting multi-scale defects.
[0042] In this example, taking the internal defect detection process of aluminum alloy castings as an example, the detection algorithm includes the following steps:
[0043] Step 1: Image Acquisition. The casting internal defect detection system consists of a high-frequency X-ray machine, a control console, an industrial-grade digital flat panel detector, a computer image processing system, a mechanical transmission control system, and a lead-lined protective system. The detection includes bubbles, porosity, shrinkage cavities, and cracks. The detection cycle is 1.2–15 frames, and the smallest resolvable deep hole is 0.3–0.4 mm. The X-ray machine's maximum penetration capability for aluminum alloys during real-time imaging can reach 80 mm. During detection, the workpiece is placed on a work platform between the X-ray source and the industrial-grade digital flat panel detector. Figure 2As shown, the control console uses a mechanical joystick to control the mechanical transmission control system (PLC, AC motor), such as controlling the left and right movement and ±360° rotation of the work platform, as well as the vertical movement and ±30° swing of the X-ray source and digital flat panel. The industrial control computer on the control console communicates point-to-point with the X-ray source via an RS-232 interface to control the X-ray intensity, and communicates with the digital flat panel detector via gigabit Ethernet to receive X-ray imaging information of the workpiece under test. Then, a computer image processing system completes functions such as image acquisition, image storage, image processing, image evaluation, and image printing. In addition, the industrial control computer is equipped with a DVD burner, which can archive the acquired image information and test results onto CDs at any time to prevent data loss. The casting internal defect detection system collected a total of 14,640 images of internal defects in aluminum alloy castings, including parts such as automotive radiator panels, chain covers, oil pans, crankcases, clutch housings, and transmission housings. The original defect images in the dataset had a resolution of 1140×1192 pixels, which were adjusted to 512×512 pixels before being used as network input. Specific defects included were porosity, shrinkage cavities, looseness, and cracks.
[0044] Step 2: The original images and files labeled with defect categories, locations, and other information are used as the original dataset. The labeled files are in PascalVOC format. To address the imbalance in the number of samples with different defects in the dataset, data augmentation is performed using methods such as rotation, horizontal flipping, random brightness adjustment, and HSV adjustment. The augmented dataset is then randomly divided into training, validation, and test sets in a ratio of 8:1:1.
[0045] Step 3: Model Training and Detection. Model training was performed on a workstation with an Intel Core i9-10900X CPU and an NVIDIA GeForce RTX 3090 GPU. The proposed model is based on the PyTorch deep learning framework, with the backbone network using a ResNet-50 residual network. Using a deeper network allows for the acquisition of deeper semantic features from defect images, and the residual block structure used in the ResNet network overcomes the problem that learning efficiency and accuracy cannot effectively improve with increasing network depth, achieving higher accuracy compared to traditional classification networks such as VGG. To reduce noise in X-ray images and interference from complex backgrounds, a CS-Block attention module, which combines channel attention and spatial attention mechanisms, was added after Conv3_x, Conv4_x, and Conv5_x. Figure 3 By further filtering the feature information in different channels and spaces in the feature map, irrelevant information is suppressed, thereby increasing the weight of the defect location area and effective feature information in the feature map and reducing the interference of background, noise and other information on defect detection.
[0046] The CS-Block module consists of a channel attention module (C-Block) and a spatial attention module (S-Block). It adds spatial dimension attention after the channel attention mechanism, improving the model's attention to the spatial location of features. Based on the characteristics of the feature maps generated by the network at different depths, the CS-Block-A structure, which uses max pooling to calculate attention, is used in shallow layers (primarily texture features) and intermediate layers (transitional features). In deeper feature maps with richer semantic information, the CS-Block-B structure, which combines max pooling and mean pooling, is used to calculate attention.
[0047] To make fuller use of the extracted features and further improve the model's detection accuracy for multi-scale defects, especially small-scale defects, a multi-scale feature fusion module using a feature pyramid network structure was added after the CS-Block module, such as... Figure 4 A horizontal connection approach is used to fuse shallow features with upsampled deep semantic information sequentially from top to bottom, constructing a multi-scale fused feature map that combines semantic information at all levels with defect location information. Then, a Conv3×3 convolutional layer is used to extract features from the generated feature map again to eliminate the aliasing effect that may be caused by the upsampling process. Finally, the multi-scale fused feature map is input into the classification and regression modules.
[0048] In the classification and regression stages, the M values obtained after convolution and fusion by Conv3×3 convolutional layers are obtained on the P3, P4, and P5 prediction feature layers. p3 M p4 M p5 Three multi-scale feature maps. Among them, M p3 The corresponding shallow texture features of the image, M p4 Corresponding to the transition features of the intermediate layer, M p5 This corresponds to deeper semantic features in the image. In M p5 Based on this, M is obtained by sequentially passing it through a Conv3×3 convolutional layer with stride=2. p6 M p7 This corresponds to the deep semantic features of the image. Finally, defect detection is performed on five predicted feature layers: P3, P4, P5, P6, and P7. The reason for starting small-scale defect detection from P3 is that the feature maps generated by Conv1 and Conv2_x are quite large, with a size at least tens of times larger than small-scale defects. Generating preselected boxes would consume a lot of computational resources. Starting small-scale defect detection from P3 reduces resource waste and improves detection efficiency.
[0049] The defect detection algorithm's predictor consists of two parts: a class subnet and a box subnet. The class subnet is responsible for predicting the target category, while the box subnet is responsible for predicting the target bounding box regression parameters. Both subnets consist of four Conv3×3 convolutional layers with stride=1 and channel=256, and one Conv3×3 convolutional layer with stride=1 and channel=36.
[0050] Step 4: K-means clustering operation. During prediction, the accuracy of defect detection is measured for each anchor point based on the Intersection over Union (IoU) of the target defect's ground truth bounding box. To obtain anchor point sizes suitable for the X-ray image dataset and improve the model's accuracy in detecting defects at different scales in the dataset, statistical analysis was performed on the ground truth boundaries of all defects in the dataset using an improved K-means clustering algorithm. When calculating the similarity between samples and clusters, 1-IoU was used as the metric, replacing the Euclidean distance in the original K-means algorithm. This resolved the error caused by the anchor box size when calculating Euclidean distance, thus improving the accuracy of the clustering results. The main calculation process is as follows:
[0051] (1) Define the number k that can be clustered into the same category;
[0052] (2) Randomly select k samples from all samples as the initial centers of the cluster;
[0053] (3) Using 1-IoU as the similarity metric between a sample and its cluster, the distance of the Ground Truth of each sample from the center of each cluster is calculated. The calculation formula is as follows:
[0054] ①Based on the image width w Image and high h Image Width of normalized Ground Truth w Ground Truth and high h Ground Truth ,Right now:
[0055]
[0056]
[0057] ②Assuming there are two Ground Truths: a and b, the IoU calculation formula for a and b is:
[0058]
[0059] In the formula: intersection(a,b) represents the area of the intersection of a and b, and union(a,b) represents the area of the union of a and b. The calculation formula is as follows:
[0060] intersection(a,b)=min(w a ,w b )×min(h a ,h b (9)
[0061] union(a,b)=w a ×h a +w b ×h b (10)
[0062] In the formula: w a h represents the width of a. a w represents the height of a. b h represents the width of b. b This represents the height of b.
[0063] (4) Compare the distance (1-IoU value) from each sample to each cluster center and assign it to the cluster with the smallest value;
[0064] (5) Calculate the mean of the width and height of all Ground Truths in each cluster as the new cluster center;
[0065] (6) Repeat steps 3 to 5 until the cluster center no longer changes, or the change value reaches the termination condition;
[0066] Based on the results of the improved K-means clustering algorithm, the cluster centers of four types of defects, namely bubbles, cracks, shrinkage cavities, and porosity, are [13, 13], [17, 15], [32, 55], and [68, 21], respectively. The scale and proportion of the anchor points are designed accordingly to obtain the maximum IoU between the anchor points and the ground truth of the defects.
[0067] Experiments show that the algorithm achieves a mean average precision (mAP) of 96.52% across all categories when the Intersection over Union (IoU) ratio is 0.5, and the detection time is only 0.024s. It can effectively achieve high-precision real-time detection of aluminum alloy castings in scenarios with high noise and complex defect backgrounds in X-ray images.
[0068] The embodiments described above are merely illustrative of implementation methods of the present invention and are not intended to limit the invention to the precise forms described. Those skilled in the art can make various modifications based on the above teachings without departing from the inventive concept. Exemplary embodiments were chosen and described to explain the specific principles of the invention and its practical applications, thereby enabling others skilled in the art to understand, implement, and utilize the various exemplary embodiments of the invention, as well as their various alternatives and modifications. The scope of protection of the present invention is intended to be defined by the appended claims and their equivalents.
Claims
1. A method for detecting internal defects in castings based on deep learning, characterized in that, Includes the following steps: Step 1: Acquire images using an internal defect detection system for castings; The casting internal defect detection system includes a high-frequency X-ray source, a control console, a digital flat panel detector, a computer image processing system, a mechanical transmission control system, and a lead-lined protective system. During detection, the workpiece is placed on a working platform between the X-ray source and the digital flat panel detector. The control console controls the mechanical transmission control system, and the industrial control computer on the control console communicates point-to-point with the X-ray source through an interface to control the X-ray intensity. It also communicates with the digital flat panel detector to receive the X-ray imaging information of the workpiece being tested. Then, the computer image processing system completes the functions of image acquisition, image storage, image processing, image evaluation, and image printing. Images of internal defects in aluminum alloy castings collected by the casting internal defect detection system. Defects include porosity, shrinkage cavities, looseness, and cracks. Step 2: Dataset Creation and Data Augmentation; The original images and files labeled with defect categories and location information are used as the original dataset. To address the issue of imbalance in the number of samples with different defects in the dataset, the dataset is augmented. The augmented dataset is then randomly divided into training, validation, and test sets. Step 3: Model building, training, and testing; The backbone network of the defect detection algorithm adopts the ResNet-50 residual network. In order to reduce the interference of noise in X-ray images and complex backgrounds, an attention module CS-Block, which combines channel attention mechanism and spatial attention mechanism, is added after Conv3_x, Conv4_x and Conv5_x. By further filtering the feature information in different channels and spaces in the feature map, irrelevant information is suppressed, thereby increasing the weight of the defect area and effective feature information in the feature map and reducing the interference of background, noise and other information on defect detection. A multi-scale feature fusion module using a feature pyramid network structure is added after the CS-Block module. It uses a horizontal connection to fuse shallow features with upsampled deep semantic information from top to bottom, constructing a multi-scale fused feature map that combines semantic information at all levels and defect location information. Then, a Conv3×3 convolutional layer is used to extract features from the generated feature map again to eliminate the aliasing effect that may be caused by the upsampling process. Finally, the multi-scale fused feature map is input into the classification and regression modules. In the classification and regression stages, M is obtained by convolution and fusion of Conv3×3 convolutional layers on the P3, P4, and P5 prediction feature layers, respectively. p3 M p4 M p5 Three multi-scale feature maps; among which, M p3 The corresponding shallow texture features of the image, M p4 Corresponding to the transition features of the intermediate layer, M p5 Corresponding to deeper semantic features of the image; in M p5 Based on this, M is obtained by sequentially passing it through a Conv3×3 convolutional layer with stride=2. p6 M p7 This corresponds to the deep semantic features of the image; finally, defect detection is performed on five predictive feature layers: P3, P4, P5, P6, and P7. The predictor of this defect detection algorithm consists of two parts: a classification subnet and a localization subnet. The class subnet is responsible for predicting the target category, and the box subnet is responsible for predicting the target bounding box regression parameters. Step 4: Improve K-means clustering operations; During prediction, the accuracy of defect detection is measured by the Intersection over Union (IoU) between the ground truth bounding box of the target defect and the ground truth bounding box. To obtain anchor point sizes suitable for the X-ray image dataset and improve the model's accuracy in detecting defects at different scales in the dataset, the ground truth bounding box boundaries of all defects in the dataset are statistically analyzed using an improved K-means clustering algorithm. When calculating the similarity between samples and clusters, 1-IoU is used as the metric to replace the Euclidean distance in the original K-means algorithm. The specific steps are as follows: (1) Define the number k that can be clustered into the same category; (2) Randomly select k samples from all samples as the initial centers of the cluster; (3) Using 1-IoU as the similarity metric between a sample and a cluster, the distance between the true bounding box of each sample and the center of each cluster is calculated; the calculation formula is as follows: ①Based on the image width w Image and high h Image The width w of the normalized true label box GroundTruth and high h GroundTruth ,Right now: ②Assuming there are two real label boxes: a and b, the IoU calculation formula for a and b is: In the formula: intersection(a,b) represents the area of the intersection of a and b, and union(a,b) represents the area of the union of a and b. The calculation formula is as follows: intersection(a,b)=min(w a ,w b )×min(h a ,h b )(4) union(a,b)=w a xh a +w b xh b (5) In the formula: w a h represents the width of a. a w represents the height of a. b h represents the width of b. b Indicates the height of b; (4) Compare the distance (1-IoU value) from each sample to each cluster center and assign it to the cluster with the smallest value; (5) Calculate the mean of the width and height of all real label boxes in each cluster as the new cluster center; (6) Repeat steps 3 to 5 until the cluster center no longer changes, or the change value reaches the termination condition.
2. The method for detecting internal defects in castings based on deep learning according to claim 1, characterized in that, During the image acquisition process in step 1, the detection cycle is 1.2 to 15 frames, the smallest resolvable deep hole is 0.3 to 0.4 mm, and the maximum penetration of the X-ray source into the aluminum alloy during real-time imaging can reach 80 mm.
3. The method for detecting internal defects in castings based on deep learning according to claim 1, characterized in that, In step 2, the dataset is augmented using rotation, horizontal flipping, random brightness adjustment, and HSV adjustment. The ratio of training set, validation set, and test set is 8:1:
1.
4. The method for detecting internal defects in castings based on deep learning according to claim 1, characterized in that, In step 3, the attention module CS-Block consists of the channel attention module C-Block and the spatial attention module S-Block. Spatial dimension attention is added after the channel attention mechanism to improve the model's attention to the spatial location of features. Based on the characteristics of the feature maps generated by the network at different depths, the CS-Block-A structure, which uses max pooling to calculate attention, is used in the shallow layers with mainly texture features and the intermediate layers with transition features. In the deep feature maps with richer semantic information, the CS-Block-B structure, which uses a combination of max pooling and average pooling to calculate attention, is used.
5. The method for detecting internal defects in castings based on deep learning according to claim 1, characterized in that, In step 3, the two sub-networks in the predictor of the defect detection algorithm each consist of four Conv3×3, stride=1, channel=256 convolutional layers and one Conv3×3, stride=1, channel=36 convolutional layer.
Citation Information
Patent Citations
X-ray weld defect detection method based on convolutional neural network
CN113674247A
Battery defect detection method and system based on deep learning
CN115170550A