Casting internal defect detection method, device, equipment, medium and product
By preprocessing the casting image and unified scale mapping, combined with the pre-trained detection model, the problem of low accuracy in casting defect detection in the prior art is solved, and more efficient and more accurate internal defect detection of castings is achieved.
Patent Information
- Application Number
- CN202510193732.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-06-10
AI Technical Summary
The existing casting defect detection methods have low accuracy in the detection results, making it difficult to effectively identify the internal defects of the casting.
A method of internal defect detection for castings is adopted, and defect detection is carried out by cropping, noise processing, binarization processing, noise filtering, void filling, connection area screening and unified scale mapping of the image to be detected, and defect detection is carried out in combination with a pre-trained internal defect detection model.
The detection efficiency and detection accuracy of internal defect detection of castings are improved, and defects inside castings can be more accurately identified.
Smart Images

Figure SMS_1 
Figure SMS_2 
Figure SMS_3
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of non-destructive testing of automotive die castings, and particularly to a method, device, equipment, medium and product for detecting internal defects of castings. Background Art
[0002] Some components of large equipment are generally cast from high-strength alloys with complex compositions due to high requirements for performance and quality. In current metal casting technology, due to the complex factors affecting metal processing quality and the difficulty of comprehensive control, there may be some internal defects in the castings that affect the functions of the castings, such as air bubbles. Therefore, detecting and identifying these internal defects is of great significance for improving the material design of castings and ensuring the performance and quality of castings.
[0003] Currently, the method for detecting casting defects mainly relies on industrial CT to detect the internal situation of the casting, and then combines manual experience to distinguish and classify the internal defects of the casting to achieve the purpose of detecting casting defects. However, this method for detecting casting defects has the problem of low accuracy of detection results. Therefore, there is an urgent need for a method for detecting casting defects with high detection accuracy. Summary of the Invention
[0004] In view of the above defects or deficiencies in the related art, the purpose of the present application is to provide a method, device, equipment, medium and product for detecting internal defects of castings, which can improve the detection efficiency and detection accuracy of detecting internal defects of castings.
[0005] To achieve the above purpose, the present application provides the following solutions:
[0006] In the first aspect, the present application provides a method for detecting internal defects of castings, including: cropping the obtained image to be detected, and performing noise processing on the cropped image to be detected by using Gaussian filtering to obtain a first image to be detected; performing binarization processing on the first image to be detected, and performing noise filtering and hole filling on the binarized first image to be detected by using morphological opening operation and morphological closing operation to obtain a second image to be detected; marking the connected regions of the second image to be detected based on a secondary traversal algorithm, and screening out the connected regions that meet the preset geometric information to obtain a third image to be detected; the preset geometric information includes area setting information or shape setting information; mapping the third image to be detected from different scales to a unified scale to obtain a target detection image; using a pre-trained internal defect detection model to perform defect detection on the target detection image to obtain the detection result of internal defects of the casting.
[0007] Optionally, the pre-trained internal defect detection model includes an input module, a backbone network, a feature extraction network, and a detection network; using the pre-trained internal defect detection model to perform defect detection on the target detection image to obtain the internal defect detection result of the casting, including: the input module obtains the target detection image; the backbone network extracts the basic features of the target detection image to obtain a plurality of basic feature maps; the feature extraction network extracts the features of the target detection image and fuses the plurality of basic feature maps by using the forward feature matrix and backward feature matrix weighted average algorithm to obtain a multi-level feature map; the detection network performs localization and recognition on the multi-level feature map and outputs the internal defect detection result of the casting.
[0008] Optionally, the pre-trained internal defect detection model is established based on a single-stage object detector; the loss function of the pre-trained internal defect detection model is the quality focal loss function; both the backbone network and the detection network are provided with a micro-scale and micro-thickness object detection module; the feature extraction network is a feature fusion network constructed by using the forward feature matrix and backward feature matrix weighted average algorithm.
[0009] Optionally, the training method of the pre-trained internal defect detection model includes: preprocessing the pre-collected original casting images to create a training data set; the training data set includes a training set, a validation set, and a test set; performing clustering processing on the training set based on a preset clustering algorithm to generate anchors adapted to the training set; training the pre-created internal defect detection model based on the training set and the anchors to obtain a first internal defect detection model; verifying the performance of the first internal defect detection model based on the validation set, adjusting the hyperparameters of the first internal defect detection model based on the verification metrics, and training the first internal defect detection model with adjusted hyperparameters until the first internal defect detection model converges or reaches a preset number of training epochs to obtain a second internal defect detection model; evaluating the performance of the second internal defect detection model based on the test set, and obtaining the trained internal defect detection model when the error between the output value of the second internal defect detection model and the target value of the test set is less than a preset threshold.
[0010] Optionally, the clustering process of the training set based on the preset clustering algorithm to generate anchors adapted to the training set includes: setting the number of clusters and randomly selecting a bounding box from the bounding boxes of the training set as the initial clustering center; calculating the distance between each bounding box of the training set and the initial clustering center, and assigning each bounding box of the training set to the cluster where the clustering center with the minimum distance is located; calculating the average value of the sizes of all bounding boxes in each cluster, and setting each cluster as the new clustering center, and performing iterative processing on the new clustering center until the number of iterations of the clustering center reaches the maximum number of iterations, then obtaining the anchors adapted to the training set.
[0011] Optionally, the quality focal loss function is:
[0012]
[0013] where ρ 2 represents the Euclidean distance between the center point of the predicted bounding box and the center point of the ground truth bounding box; C is the diagonal length of the smallest bounding box containing the predicted bounding box and the ground truth bounding box; w gt and h gt represent the width and height of the ground truth bounding box respectively, and w and h represent the width and height of the predicted bounding box respectively.
[0014] In a second aspect, the present application provides a casting internal defect detection device, including:
[0015] A first image processing module, configured to crop the acquired image to be detected, and perform noise processing on the cropped image to be detected by using Gaussian filtering to obtain a first image to be detected;
[0016] A second image processing module, configured to perform binarization processing on the first image to be detected, and perform noise filtering and hole filling on the binarized first image to be detected by using morphological opening operation and morphological closing operation to obtain a second image to be detected;
[0017] A third image processing module, configured to label the connected regions of the second image to be detected based on a secondary traversal algorithm, and screen out the connected regions that meet the preset geometric information to obtain a third image to be detected; the preset geometric information includes area setting information or shape setting information;
[0018] A fourth image processing module, configured to map the third image to be detected to a unified scale from different scales to obtain a target detection image;
[0019] A detection module, configured to perform defect detection on the target detection image by using a pre-trained internal defect detection model to obtain a casting internal defect detection result.
[0020] In a third aspect, the present application provides a computer device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor executes the computer program to implement the steps of the casting internal defect detection method described in any one of the above.
[0021] In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the casting internal defect detection method described in any one of the above.
[0022] In a fifth aspect, the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the steps of the casting internal defect detection method described in any one of the above.
[0023] According to the specific embodiments provided by the present application, the following technical effects are disclosed in the present application:
[0024] The present application provides a casting internal defect detection method, device, equipment, medium and product. By cropping, noise processing, binarization processing, noise filtering, hole filling, connected region screening and unified scale for the acquired image to be detected, the image quality of the image to be detected can be improved, and further the detection speed and the accuracy of the detection result of the pre-trained internal defect detection model can be improved, so as to achieve the purpose of improving the detection efficiency and detection accuracy of casting internal defects. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required to be used in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0026] Figure 1 It is a schematic flowchart of a casting internal defect detection method provided by an embodiment of the present application;
[0027] Figure 2 It is a schematic structural diagram of a pre-trained internal defect detection model provided by an embodiment of the present application;
[0028] Figure 3 For Figure 2 a partial structural schematic diagram of the pre-trained internal defect detection model;
[0029] Figure 4 It is a schematic structural diagram of a backbone network provided by an embodiment of the present application Figure 1 ;
[0030] Figure 5 Structural schematic of the backbone network provided by an embodiment of the present application Figure 2 ;
[0031] Figure 6 Structural schematic of the backbone network provided by an embodiment of the present application Figure 3 ;
[0032] Figure 7 Schematic diagram of the structure of the feature fusion network provided by an embodiment of the present application;
[0033] Figure 8 Schematic of an image sample of the training dataset provided by an embodiment of the present application Figure 1 ;
[0034] Figure 9 Schematic of an image sample of the training dataset provided by an embodiment of the present application Figure 2 ;
[0035] Figure 10 Size distribution diagram of bubble defects in the training dataset provided by an embodiment of the present application;
[0036] Figure 11 Schematic diagram of the functional modules of a casting internal defect detection device provided by an embodiment of the present application;
[0037] Figure 12 Schematic diagram of the structure of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0038] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0039] To make the above objects, features, and advantages of the present application more obvious and understandable, the present application will be further described in detail below in conjunction with the accompanying drawings and specific implementation manners.
[0040] In modern manufacturing, the quality control of castings is a key link to ensure product performance and safety. Defect detection, as an important part of quality control, is crucial for identifying and classifying defects on the surface or inside of castings. The casting defect detection method mainly relies on industrial CT to explore the internal situation of the casting, and then combines manual experience to discriminate and classify the internal defects of the casting to achieve the purpose of completing the casting defect detection. This method is usually time-consuming and vulnerable to the skills and fatigue of the operator, so the accuracy and efficiency are relatively low.
[0041] In an exemplary embodiment, as Figure 1 shown, a method for detecting internal defects of a casting is provided. This method is executed by a computer device, specifically, it can be executed alone by a computer device such as a terminal or a server, or jointly executed by a terminal and a server. In the embodiment of the present application, the method for detecting internal defects of a casting includes the following steps S110 to step S150. Among them:
[0042] Step S110: Crop the obtained image to be detected, and perform noise processing on the cropped image to be detected using Gaussian filtering to obtain a first image to be detected.
[0043] In the exemplary embodiment, the image to be detected is an X-ray image. Gaussian filtering uses a Gaussian function as a weight matrix to smooth the image to be detected. Among them, the degree of filtering can be controlled by adjusting the size of the Gaussian kernel and the standard deviation of the Gaussian function, so as to retain the important features of the image to be detected as much as possible while removing noise. In this embodiment, the important features of the image to be detected can be air bubbles, cracks, etc. of the casting.
[0044] Step S120: Perform binarization processing on the first image to be detected, and use morphological opening operation and morphological closing operation to filter out noise points and fill holes in the binarized first image to be detected to obtain a second image to be detected.
[0045] In the exemplary embodiment, binarization processing converts the image to be detected from a gray image into a binary image with only two colors, black and white, which is convenient for subsequent marking of the connected regions of the second detected image. Both the morphological opening operation and the morphological closing operation are a combination of operations, both consisting of two steps: erosion and dilation; erosion is to use a structuring element to erode the binary image to remove the protruding parts in the binary image, which can eliminate small noise points. Dilation is to dilate the eroded image to restore the eroded part, but not the removed noise points. Among them, the purpose of the morphological opening operation is to remove small noise points and separate adjacent objects; the purpose of the morphological closing operation is to fill small holes and connect adjacent objects.
[0046] Step S130: Mark the connected regions of the second image to be detected based on the secondary traversal algorithm, and screen out the connected regions that meet the pre-set geometric information to obtain a third image to be detected.
[0047] In an exemplary embodiment, the preset geometric information includes area setting information or shape setting information. A connected region refers to a set of adjacent pixels composed of the same pixel value (usually white or black), and a two-pass algorithm is used to identify and label these connected regions. Among them, the two-pass algorithm includes a first pass and a second pass. In the first pass stage, for each pixel in the second image to be detected, it is checked whether it is a foreground pixel (usually white); if it is a foreground pixel, it is checked whether the 8 adjacent pixels around this pixel have been labeled; if there are already labeled adjacent pixels around, the current pixel is labeled with the label that appears most frequently among the adjacent pixels; if there are no labeled adjacent pixels around, a new label is assigned to the current pixel. In the second pass stage, the entire second image to be detected is traversed again, and the labels assigned during the first pass are screened according to the area setting information or shape setting information to select the appropriate connected regions.
[0048] Step S140, map the third image to be detected from different scales to a unified scale to obtain the target detection image.
[0049] As can be understood in combination with the above embodiments, for example, the image to be detected is centered and cropped to 640×640 pixels, and Gaussian filtering with a kernel diameter of 5×5 is used to remove the Gaussian noise of the image to be detected, such as particle noise on the fluorescent screen, to obtain the first image to be detected. Then, the OTSU algorithm is used to determine the threshold for binary segmentation, and morphological opening operation and morphological closing operation are applied to the segmented image to filter out noise and fill holes in the second image to be detected, obtaining the second image to be detected. Then, the two-pass algorithm is used to label the contours of all connected regions, and the required image is screened according to the preset geometric information, that is, the third image to be detected is obtained. Then, the third image to be detected is mapped from different scales to a unified scale by using a homography transformation to obtain the target detection image. That is, assuming a pair of corresponding points (x, y) and (x', y'), where (x, y) is the coordinate in the third image to be detected and (x', y') is the coordinate in the target detection image, the homography transformation can be expressed by the following formula (1):
[0050]
[0051] Among them, h1, ..., h8 are the transformation parameters in the homography transformation matrix H. The homography transformation matrix H is an unknown matrix. To calculate the homography transformation matrix H, at least four pairs of non-collinear corresponding points are required. For example, based on an approximate algorithm, the minimum bounding rectangle of the third image to be detected is solved, and the four corner points of the minimum bounding rectangle are used as reference points to establish a system of linear equations with eight equations. The system of linear equations with eight equations is solved by the least squares method to obtain the homography transformation matrix H. Among them, the homography transformation matrix H represents the linear transformation between the third image to be detected and the target detection image, including rotation, scaling, translation, and perspective transformation.
[0052] Step S150, use the pre-trained internal defect detection model to detect defects in the target detection image to obtain the casting internal defect detection result.
[0053] In the exemplary embodiment, the casting internal defect detection results include bubbles, cracks, and pores, etc.
[0054] The pre-trained internal defect detection model is based on a single-stage object detector. Among them, the single-stage object detector (You Only Look Once, YOLO) regards object detection as a regression problem and directly predicts the bounding box and class probability from the input image, thus realizing end-to-end detection.
[0055] As Figure 2 shown, the pre-trained internal defect detection model includes an input module 210, a backbone network 220, a feature extraction network 230, and a detection network 240.
[0056] Specifically, the input module 210 uses the K-means++ algorithm to cluster the input target detection image to generate predefined bounding boxes, and uses the predefined bounding boxes to calibrate the boundaries of the target detection image; it can ensure that the pre-trained internal defect detection model can effectively extract the defects in the casting X-ray image. The backbone network 220 is as Figure 2 shown, adding a micro-scale detection head CBS, which can detect small-sized and irregularly shaped defects, and improve the ability of the pre-trained internal defect detection model to detect small defects. The feature extraction network 230 introduces a weighted average mechanism for the forward feature matrix and the backward feature matrix; by introducing the weighted average mechanism for the forward feature matrix and the backward feature matrix, semantic features from different levels can be fused to extract complex and irregular defect features, further improving the detection ability of the pre-trained internal defect detection model; for example Figure 3As shown, the direction indicated by the arrow represents the direction of the feature stream. The feature extraction network 230 transfers and fuses the feature maps in the backbone network 220 and the feature extraction network 230 according to the direction of the feature stream. The detection network 240 involves a part that uses the quality focal loss function instead of the cross-entropy loss function to solve the problem of imbalance between positive and negative samples and improve the detection effect and robustness of the pre-trained internal defect detection model.
[0057] Furthermore, both the backbone network 220 and the detection network 240 are provided with a micro-scale and micro-thickness object detection module.
[0058] It can be understood that the backbone network of a conventional single-stage object detector adopts an FPN (Feature Pyramid Network) structure and a PAN (Path Aggregation Network) structure to combine the features of different layers. The backbone network in the embodiments of the present application is created on the basis of the backbone network of a conventional single-stage object detector. As Figure 4 shown, in the FPN structure of the embodiments of the present application, instead of using the 4× downsampled feature layer based on the original backbone network for feature fusion, a module CBS is inserted between the 2× and 4× downsampled feature layers, which can maintain deeper semantic information but does not conceal the use of shallow position and detail information; and the four scaled feature layers of the backbone network in the embodiments of the present application can extract features containing long-strip and irregular bubble defects, achieving the purpose of improving the feature extraction ability. As Figure 5 shown, the PAN structure in the embodiments of the present application adds a bottom-up downsampling path for matching the FPN structure, which can maintain deeper semantic information and shallower position information; that is, the feature extraction network of the present application can retain more semantic features by introducing a weighted average mechanism of the forward feature matrix and the backward feature matrix, and performing feature fusion of different layers using the PANet network and the FPN network. The final output size of the feature extraction network is 160×160.
[0059] In addition, there are three detection heads in the detection network of a conventional single-stage object detector. As Figure 2 shown, the detection network in the embodiments of the present application adds a micro-scale detection head on the basis of the detection network of a conventional single-stage object detector.
[0060] It should be noted that Figure 2 and Figure 3 the CBS in refers to the convolutional layer, batch normalization layer, and Swish activation function.
[0061] Further, the feature extraction network is a feature fusion network constructed using the weighted average algorithm of the forward feature matrix and the backward feature matrix.
[0062] It can be understood that, as Figure 7 shown in the topological structure of the feature fusion network, where the feature fusion technology still merges by the number of channels. In Figure 7 , the feature layers obtained when the backbone network downsamples at 4×, 8×, 16×, and 32× are shown as P2,1 - P5,1. In the feature fusion network constructed in this application, the feature fusion layer P2,2 of the second layer and the feature fusion layer P5,2 of the fifth layer are cancelled, and two skip connection lines are introduced. One is from the feature fusion layer P3,1 to the feature fusion layer P3,3; the other is from the feature fusion layer P4,1 to the feature fusion layer P4,3.
[0063] In the feature fusion network, the weighted average algorithm of the forward feature matrix and the backward feature matrix is used to fuse features from multiple scales. Specifically, the weighted average algorithm of the forward feature matrix and the backward feature matrix is the following formula (2):
[0064]
[0065] where the above formula (2) is optimal in the sense of minimizing the weighted curve fitting parameter error J = eb(A - A)T(A - A) + er(a - Ab)T(A - A), where a, er, Ab, eb are respectively given by given.
[0066] Further, the loss function of the pre-trained internal defect detection model is the quality focal loss function. Among them, the quality focal loss function is:
[0067]
[0068] where ρ 2 represents the Euclidean distance between the center point of the predicted box and the center point of the true box; D is the diagonal length of the smallest bounding box containing the predicted box and the true box; w gt and h gt respectively represent the width and height of the true box, and w and h respectively represent the width and height of the predicted box.
[0069] By replacing the cross-entropy loss function of the conventional single-stage object detector with the quality focal loss function, the imbalance problem between positive and negative samples can be solved.
[0070] In a specific embodiment, the above step S150 may include: an input module obtains a target detection image; a backbone network extracts basic features of the target detection image to obtain a plurality of basic feature maps; a feature extraction network extracts features of the target detection image and fuses the plurality of basic feature maps by using a forward feature matrix and a backward feature matrix weighted average algorithm to obtain a multi-level feature map; a detection network performs positioning and recognition on the multi-level feature map and outputs a detection result of internal defects of the casting.
[0071] In a specific embodiment, the training method of a pre-trained internal defect detection model may include steps S310 to S350, where:
[0072] Step S310, preprocesses the pre-collected original casting images to create a training data set; the training data set includes a training set, a validation set, and a test set.
[0073] In an exemplary embodiment, the preprocessing of the pre-collected original casting images includes: cropping, noise processing, noise point filtering, hole filling, connected region screening, and uniform scaling of the original casting images to obtain images that meet the processing requirements of the pre-constructed internal defect detection model, and marking these preprocessed images as image samples, such as the image samples Figure 8 and Figure 9 shown. In Figure 8 and Figure 9 , bounding boxes are used to locate and mark the defects of the image samples, which is convenient for subsequent training, validation, and performance evaluation of the pre-constructed internal defect detection model.
[0074] It should be noted that if the number of image samples in the training data set of this embodiment is 1000, the ratio of the number of image samples in the training set, the validation set, and the test set is 7:2:1. And the size distribution of bubble defects in the training data set is as shown in Figure 10 , and by increasing the number of small-size image samples, the accuracy of the pre-trained internal defect detection model for detecting small-size defects can be effectively improved.
[0075] Step S320, performs clustering processing on the training set based on a preset clustering algorithm to generate anchors adapted to the training set.
[0076] It can be understood that the above step S320 may include: setting the number of clusters and randomly selecting a bounding box from the bounding boxes of the training set as the initial clustering center; calculating the distance between each bounding box of the training set and the initial clustering center, and assigning each bounding box of the training set to the cluster where the clustering center with the minimum distance is located; calculating the average value of the sizes of all bounding boxes in each cluster, and setting each cluster as the new clustering center, and performing iterative processing on the new clustering center until the number of iterations of the clustering center reaches the maximum number of iterations, then the anchor points adapted to the training set are obtained.
[0077] Further, it can be understood that, for example, first, randomly select a value B from the training set as the initial clustering center C. Second, calculate the minimum IOU distance d(x) between each sample x and the existing clustering center C, as shown in formula (3); determine the probability that each sample will be used as the subsequent clustering center, denoted by p(x), as shown in formula (3); and use the roulette method to select the next clustering center, where samples with a higher probability have a greater chance of being selected. Third, repeatedly use the roulette method to select the next clustering center until there are K clustering centers. Fourth, calculate the IOU distance from each sample in the training set to the K clustering centers, and assign each sample in the training set to the cluster corresponding to the clustering center with the shortest distance. Fifth, calculate the average width and height of each cluster, and use these values as the new K clustering centers. Sixth, repeat the above fourth and fifth until there is no change in the position of the clustering center, then the required anchor boxes are obtained.
[0078] Among them, the above d(x) and p(x) are defined as follows:
[0079] d(x) = 1 - IoU(x, C)
[0080]
[0081] Where x = (w1, h1), C = (w2, h2), and IOU represents the intersection over union between the sampling point x and the clustering center C, ranging from 0 to 1. Where w represents the width of the prediction box and h represents the height of the prediction box.
[0082] If the sampling point x and the clustering center C are similar, then the IOU will be larger. The IOU is defined as the following formula (4):
[0083]
[0084] Step S330, train the pre-created internal defect detection model based on the training set and the anchor points to obtain the first internal defect detection model.
[0085] Step S340: Verify the performance of the first internal defect detection model based on the validation set, adjust the hyperparameters of the first internal defect detection model based on the verification metrics, and train the first internal defect detection model with adjusted hyperparameters until the first internal defect detection model converges or reaches the preset number of training rounds, so as to obtain the second internal defect detection model.
[0086] Step S350: Evaluate the performance of the second internal defect detection model based on the test set. When the error between the output value of the second internal defect detection model and the target value of the test set is less than the preset threshold, obtain the trained internal defect detection model.
[0087] It should be noted that the preset threshold is associated with the quality focus loss function, and the specific value can be set according to actual applications. This application embodiment does not make any limitations.
[0088] By implementing the above steps S110 to S150, the image quality of the acquired image to be detected can be improved by performing cropping, noise processing, binarization processing, noise filtering, hole filling, connected region screening, and unified scaling on the acquired image to be detected. Furthermore, the detection speed and the accuracy of the detection result of the pre-trained internal defect detection model can be improved, so as to achieve the purpose of improving the detection efficiency and detection accuracy of internal defects in castings.
[0089] Based on the same inventive concept, the embodiment of the present application further provides a casting internal defect detection device for implementing the above-mentioned casting internal defect detection method. The implementation solution provided by this device to solve problems is similar to the implementation solution described in the above method. Therefore, the specific limitations in one or more embodiments of the following casting internal defect detection device can refer to the limitations on the casting internal defect detection method in the above text, and will not be repeated here.
[0090] In an exemplary embodiment, as Figure 11 shown, a casting internal defect detection device is provided. The casting internal defect detection model 300 includes:
[0091] A first image processing module 310, configured to crop the acquired image to be detected, and perform noise processing on the cropped image to be detected by using Gaussian filtering to obtain a first image to be detected;
[0092] A second image processing module 320, configured to perform binarization processing on the first image to be detected, and perform noise filtering and hole filling on the binarized first image to be detected by using morphological opening operation and morphological closing operation to obtain a second image to be detected;
[0093] The third image processing module 330 is configured to label the connected regions of the second image to be detected based on a secondary traversal algorithm, and filter out the connected regions that meet the preset geometric information to obtain a third image to be detected; the preset geometric information includes area setting information or shape setting information;
[0094] The fourth image processing module 340 is configured to map the third image to be detected to a unified scale from different scales to obtain a target detection image;
[0095] The detection module 350 is configured to perform defect detection on the target detection image by using a pre-trained internal defect detection model to obtain a casting internal defect detection result.
[0096] As an optional implementation manner, the above-mentioned pre-trained internal defect detection model includes an input module, a backbone network, a feature extraction network, and a detection network; wherein, the detection module 350 can also be used to obtain the target detection image by the input module; the backbone network extracts the basic features of the target detection image to obtain multiple basic feature maps; the feature extraction network extracts the features of the target detection image and fuses multiple basic feature maps by using a forward feature matrix and a backward feature matrix weighted average algorithm to obtain a multi-level feature map; the detection network performs localization and recognition on the multi-level feature map and outputs a casting internal defect detection result.
[0097] As an optional implementation manner, the above-mentioned pre-trained internal defect detection model is established based on a single-stage object detector; the loss function of the pre-trained internal defect detection model is a quality focal loss function; both the backbone network and the detection network are provided with a micro-scale and micro-thickness object detection module; the feature extraction network is a feature fusion network constructed by using a forward feature matrix and a backward feature matrix weighted average algorithm.
[0098] As an optional implementation manner, the training method of the above-mentioned pre-trained internal defect detection model includes: preprocessing the pre-collected original casting images to create a training data set; the training data set includes a training set, a validation set, and a test set; performing clustering processing on the training set based on a preset clustering algorithm to generate anchors adapted to the training set; training the pre-created internal defect detection model based on the training set and the anchors to obtain a first internal defect detection model; verifying the performance of the first internal defect detection model based on the validation set, and adjusting the hyperparameters of the first internal defect detection model based on the verification metrics, and training the first internal defect detection model with adjusted hyperparameters until the first internal defect detection model converges or reaches a preset number of training rounds to obtain a second internal defect detection model; evaluating the performance of the second internal defect detection model based on the test set, and obtaining a trained internal defect detection model when the error between the output value of the second internal defect detection model and the target value of the test set is less than a preset threshold.
[0099] As an alternative implementation, the above-mentioned clustering process of the training set based on the preset clustering algorithm to generate anchors adapted to the training set includes: setting the number of clusters and randomly selecting a bounding box from the bounding boxes of the training set as the initial clustering center; calculating the distance between each bounding box of the training set and the initial clustering center, and assigning each bounding box of the training set to the cluster where the clustering center with the minimum distance is located; calculating the average value of the sizes of all bounding boxes in each cluster, and setting each cluster as the new clustering center, and performing iterative processing on the new clustering center until the number of iterations of the clustering center reaches the maximum number of iterations, then obtaining the anchors adapted to the training set.
[0100] As an alternative implementation, the above-mentioned quality focal loss function is:
[0101]
[0102] where ρ 2 represents the Euclidean distance between the center point of the predicted box and the center point of the ground truth box; D is the diagonal length of the smallest bounding box containing the predicted box and the ground truth box; w gt and h gt represent the width and height of the ground truth box respectively, and w and h represent the width and height of the predicted box respectively.
[0103] Among them, by implementing this implementation method, through operations such as cropping, noise processing, binarization processing, noise filtering, hole filling, connected region screening, and unified scaling on the obtained image to be detected, the image quality of the image to be detected can be improved, and further, the detection speed and the accuracy of the detection result of the pre-trained internal defect detection model can be improved, so as to achieve the purpose of improving the detection efficiency and detection accuracy of internal defects in castings.
[0104] In an exemplary embodiment, a computer device is provided. The computer device can be a server or a terminal, and its internal structure diagram can be as Figure 12As shown in the figure. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O), and a communication interface. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store video tag processing data. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals through a network connection. When the computer program is executed by the processor, it implements a method for detecting internal defects of castings.
[0105] Those skilled in the art can understand that Figure 12 the structure shown in the figure is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0106] In an exemplary embodiment, a computer device is further provided, including a memory and a processor. A computer program is stored in the memory, and when the processor executes the computer program, the steps in the above method embodiments are implemented.
[0107] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program, and when the computer program is executed by the processor, the steps in the above method embodiments are implemented.
[0108] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by the processor, the steps in the above method embodiments are implemented.
[0109] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with relevant regulations.
[0110] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0111] The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processors, graphics processors, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0112] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered to be within the scope described in this specification.
[0113] Specific examples are used in this article to elaborate on the principles and implementation manners of the present application. The descriptions of the above embodiments are only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. A method for detecting internal defects of castings, characterized in that: The casting internal defect detection method comprises: The acquired image to be detected is cropped, and a noise process is performed on the cropped image to be detected by using a Gaussian filter to obtain a first image to be detected; Binarizing the first image to be detected, and performing noise filtering and hole filling on the first image to be detected after the binarization processing by using morphological opening operation and morphological closing operation to obtain a second image to be detected; Based on the secondary traversal algorithm, the connected areas of the second image to be detected are marked, and the connected areas satisfying the preset geometric information are screened out to obtain the third image to be detected; the preset geometric information includes area setting information or shape setting information; Mapping the third image to be detected from different scales to a unified scale to obtain a target detection image; The target detection image is subjected to defect detection using a pre-trained internal defect detection model to obtain a casting internal defect detection result.
2. The method for detecting internal defects of castings according to claim 1, characterized in that: The pre-trained internal defect detection model includes an input module, a backbone network, a feature extraction network and a detection network; The method of performing defect detection on the target detection image using a pre-trained internal defect detection model to obtain a casting internal defect detection result includes: The input module obtains the target detection image; The backbone network extracts basic features of the target detection image to obtain multiple basic feature maps; The feature extraction network extracts the features of the target detection image, and fuses the multiple basic feature maps using a forward feature matrix and a backward feature matrix weighted average algorithm to obtain a multi-level feature map; The detection network locates and identifies the multi-level feature map and outputs the casting internal defect detection result.
3. The method for detecting internal defects of castings according to claim 2, characterized in that: The pre-trained internal defect detection model is established based on a single-stage target detector; the loss function of the pre-trained internal defect detection model is a quality focus loss function; the backbone network and the detection network are both provided with a micro-scale micro-thickness object detection module; the feature extraction network is a feature fusion network constructed using a weighted average algorithm of a forward feature matrix and a backward feature matrix.
4. The method for detecting internal defects of castings according to claim 1, characterized in that: The training method of the pre-trained internal defect detection model includes: Preprocessing the pre-collected original casting images to create a training data set; the training data set includes a training set, a verification set and a test set; Performing clustering processing on the training set based on a preset clustering algorithm to generate anchor points adapted to the training set; Training a pre-created internal defect detection model based on the training set and the anchor point to obtain a first internal defect detection model; Verifying the performance of the first internal defect detection model based on the verification set, adjusting the hyperparameters of the first internal defect detection model based on the verification index, and training the first internal defect detection model after adjusting the hyperparameters until the first internal defect detection model converges or reaches a preset training round, to obtain a second internal defect detection model; The performance of the second internal defect detection model is evaluated based on the test set, and the trained internal defect detection model is obtained when the error between the output value of the second internal defect detection model and the target value of the test set is less than a preset threshold.
5. The method for detecting internal defects of castings according to claim 4, characterized in that: The clustering process is performed on the training set based on a preset clustering algorithm to generate anchor points adapted to the training set, including: Setting the number of clusters and randomly selecting a bounding box from the bounding boxes of the training set as an initial clustering center; Calculating the distance between each bounding box of the training set and the initial cluster center, and assigning each bounding box of the training set to the cluster where the cluster center with the smallest distance is located; The average value of all bounding box sizes in each cluster is calculated, and each cluster is set as a new cluster center. The new cluster center is iteratively processed until the number of iterations of the cluster center reaches the maximum number of iterations, thereby obtaining an anchor point adapted to the training set.
6. The method for detecting internal defects of castings according to claim 3, characterized in that: The quality focus loss function is: Among them, ρ 2 represents the Euclidean distance between the center point of the predicted box and the center point of the real box; D is the diagonal length of the smallest bounding box containing the predicted box and the real box; w gt and h gt They represent the width and height of the real box, w and h represent the width and height of the predicted box, respectively.
7. A casting internal defect detection device, characterized in that: The casting internal defect detection device comprises: A first image processing module, used for cropping the acquired image to be detected, and performing noise processing on the cropped image to be detected by using Gaussian filtering to obtain a first image to be detected; A second image processing module is used to perform a binarization process on the first image to be detected, and use a morphological opening operation and a morphological closing operation to perform noise filtering and hole filling on the first image to be detected after the binarization process, so as to obtain a second image to be detected; A third image processing module is used to mark the connected areas of the second image to be detected based on a quadratic traversal algorithm, and screen out the connected areas that meet the preset geometric information to obtain a third image to be detected; the preset geometric information includes area setting information or shape setting information; A fourth image processing module, used for mapping the third to-be-detected image from different scales to a unified scale to obtain a target detection image; The detection module is used to perform defect detection on the target detection image using a pre-trained internal defect detection model to obtain a casting internal defect detection result.
8. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method for detecting internal defects of castings according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for detecting internal defects of castings according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for detecting internal defects of castings according to any one of claims 1 to 6 are implemented.