A metal casting surface defect detection method based on improved YOLOX-S algorithm
By improving the ES-PAFPN network feature fusion mechanism of the YOLOX-S algorithm, the semantic difference problem in surface defect detection of metal castings is solved, the detection accuracy and efficiency are improved, and it is suitable for the automated detection of surface defects of metal castings.
Patent Information
- Application Number
- CN202211678195.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-26
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2042-12-26
AI Technical Summary
The existing YOLOX-S algorithm has semantic differences in the detection of surface defects of metal castings, resulting in low detection accuracy, especially poor detection effect for dense defects.
The improved YOLOX-S algorithm is used to construct an ES-PAFPN network for feature fusion, and the feature extraction network extracted features are processed using erasing and strengthening mechanisms, and combined with transfer learning and data enhancement technology to improve detection accuracy.
It effectively solves the problem of semantic differences, improves the network's detection accuracy for dense defects, reduces the missed detection rate, and improves detection efficiency and accuracy.
Smart Images

Figure CN115797326B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of defect recognition, and in particular relates to a metal casting surface defect detection method based on an improved YOLOX-S algorithm. Background Art
[0002] With the booming development of my country's heavy industry, the manufacturing industry is increasingly demanding metal castings. The appearance of metal castings directly impacts the quality of the finished product. Raw materials undergo a series of production processes to produce a batch of metal parts. However, due to the inability to perfectly fit the mold and the raw materials, many surface defects, such as dents and holes, can appear on the metal parts. Finished products assembled from defective metal parts can directly affect their appearance and significantly reduce their performance, rendering them suboptimal. Therefore, promptly identifying and remediating defective areas is crucial.
[0003] Currently, the primary method for detecting surface defects in metal castings is still manual inspection. Workers visually identify surface defects, fill the corresponding defective areas, and then finely polish the casting surface to meet product requirements. However, manual inspection also presents numerous challenges. Long periods of repetitive, monotonous work can cause worker fatigue, leading to increased missed detection rates and product rejection rates, which directly impact the performance of finished products. Therefore, a method for detecting surface defects in metal castings that can reduce production costs and improve efficiency could significantly improve the manufacturing industry.
[0004] With the continuous improvement of hardware computing power and the continuous innovation of algorithm models, the introduction of deep learning has greatly improved the accuracy of defect detection and reduced the cost of designing defect detection systems. In the field of supervised object detection, there are two main types of algorithms: one-stage object detection algorithms and two-stage object detection algorithms. Both of them enable network models to identify defect categories by learning from a large number of labeled defect samples. The one-stage algorithm is faster and more accurate than the two-stage algorithm, meeting the speed and accuracy requirements of defect detection in actual production.
[0005] YOLOX-S is an efficient, one-stage object detection network that achieves good detection results. However, the original YOLOX-S neck network uses a direct fusion approach, which suffers from semantic discrepancies and presents challenges in detecting dense defects. The features of different defect types can affect each other, reducing network accuracy. Summary of the Invention
[0006] The purpose of this paper is to provide a method for detecting surface defects in metal castings based on an improved YOLOX-S algorithm, addressing the semantic discrepancy problem inherent in feature fusion networks. This algorithm can effectively reduce the uncertainty associated with manual inspection and improve the accuracy of defect detection, facilitating subsequent defect area filling.
[0007] The purpose of the present invention is achieved through such technical solution, and the specific steps are as follows:
[0008] 1) Data acquisition: Collect several metal casting surface images in the database to construct a metal casting surface dataset;
[0009] 2) Data preprocessing: Preprocess the data in the metal casting surface dataset and divide the processed dataset into training and test sets in proportion;
[0010] 3) Model construction: Build a metal casting surface defect detection model based on the improved YOLOX-S network;
[0011] 4) Model training: Use the dataset to train a metal casting surface defect detection model based on the improved YOLOX-S algorithm;
[0012] 5) Defect Detection: The surface image of the metal casting to be inspected is input into the trained improved YOLOX-S network to obtain a result image containing the defect category and defect location.
[0013] Furthermore, the specific steps of data preprocessing in step 2) are:
[0014] 2-1) performing an enhancement operation on the metal casting surface dataset, wherein the enhancement operation includes but is not limited to flipping and cropping;
[0015] 2-2) Use LabelImg software to label the enhanced dataset, construct a VOC format dataset, and divide the constructed VOC format dataset into a training set and a test set in a ratio of 8:2.
[0016] Furthermore, the improved YOLOX-S network in step 3) includes a backbone network, a neck network, and a head network;
[0017] The backbone network is a feature extraction network composed of the CSPDarknet network, the neck network is a feature fusion network composed of the improved PAFPN network - ES-PAFPN network, and the head network is a classification prediction network composed of three YOLO Head networks;
[0018] The ES-PAFPN network adopts erasing and strengthening mechanism to perform indirect feature fusion.
[0019] Furthermore, the feature extraction network is composed of a CSPDarknet network including four Resblock body blocks connected in series for extracting features from the input image layer by layer;
[0020] Each Resblock body block is used to reduce the image size by half and double the number of channels; the last Resblock body block of the series network includes an SPP network structure used to improve the receptive field of the network;
[0021] The feature extraction network extracts three features: Feature0, Feature1, and Feature2.
[0022] Furthermore, the feature fusion network is composed of an ES-PAFPN network, which includes two parts: bottom-up and up-bottom. The bottom-up part uses an erasing and strengthening mechanism to process the features extracted by the feature extraction network and inputs the results into the up-bottom part to further strengthen the features.
[0023] The feature fusion network ES-PAFPN inputs the three-layer features Feature0, Feature1, and Feature2 extracted by the feature extraction network; Feature0 is resized to the same size as Feature1 by the CU2 unit, and the attention mechanism CBAM is used to find the sub-feature information of Feature0 implicit in the sub-feature of Feature1. Erased feature1 and strengthened feature0 are then obtained through the erasing and enhancement mechanism. At the same time, a gating unit is introduced and the tanh activation function is used to reflect the degree of mutual influence between sub-features. According to the above method, erased feature2 and strengthened feature0 are obtained through Feature1 and Feature2.
[0024] The bottom-up part only uses the strengthening mechanism and outputs Erased feature2, Erased feature1 and Strengthened feature0; the bottom-up part outputs Erased feature2, Erased feature1 and Strengthened feature0; the bottom-up part represents:
[0025] F2 Erased =Era(Slice(F2),Slice(CU1(F1)))
[0026] F1 Erased=Str(Slice(F2),Slice(CU1(F1)))
[0027] +Era(Slice(F1),Slice(CU2(F0)))
[0028] F0 Strengthened =Str(Slice(F1),Slice(CU2(F0)))
[0029] Where F1, F2, and F3 are input features, Era represents the erasure mechanism, Str represents the strengthening mechanism, Slice represents the feature slicing operation, and CU1 and CU2 represent convolution modules.
[0030] The input of the up-bottom part is the output of the bottom-up part. The up-bottom part only strengthens the features again through the strengthening mechanism. The up-bottom part can be expressed by the following formula:
[0031] F1 Final =Str(Slice(F1 Erased ),Slice(DC1(F2 Erased )))
[0032] F0 Final =Str(Slice(F0 Strengthened ),Slice(DC2(F1 Final )))
[0033] Where, F1 Erased , F2 Erased , F0 Strengthened , F1 Fional is the input feature, Str represents the strengthening mechanism, Slice represents the feature slicing operation, DC1 and DC2 represent the convolution module;
[0034] The outputs of the ES-PAFPN are Erased feature 2, Final feature 1, and Final feature 0.
[0035] Furthermore, the classification prediction network is composed of three YOLO Head networks. The YOLO Head network adopts a decoupled head structure. The YOLO Head network includes three parts: Reg part, Obj part, and Cls part.
[0036] The Reg part is used to represent the offset of the center point of the prediction box and the width and height information of the prediction box, the Obj part is used to represent the probability that the prediction box contains an object, and the Cls part is used to represent the probability that the prediction box corresponds to a certain type of defect.
[0037] Furthermore, the specific method of model training in step 4) is:
[0038] 4-1) Using the transfer learning method, pre-training is performed on the training set of the VOC dataset, and then the pre-trained weights are used in this metal surface casting defect detection network;
[0039] 4-2) Input the test set data into the metal surface casting defect detection network obtained in step 4-1), and take the weight with the highest test set accuracy as the weight of the trained improved YOLOX-S network.
[0040] Due to the adoption of the above technical solution, the present invention has the following advantages:
[0041] This application builds a metal casting surface defect detection network based on a deep learning target detection algorithm and an improved YOLOX-S algorithm for metal casting surface defects. This network effectively addresses the semantic discrepancy problem of the original YOLOX-S network through erasure and reinforcement mechanisms, improving the network's detection accuracy for dense defects and providing a technical reference for filling surface defects in metal castings.
[0042] Other advantages, objectives, and features of the present invention will be described in part in the following description and, in part, will be apparent to those skilled in the art upon examination of the following description or may be learned from practice of the present invention. The objectives and other advantages of the present invention may be realized and obtained through the following description and claims. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings of the present invention are described below.
[0044] Figure 1 This is a flow chart of the metal casting surface defect detection method based on the improved YOLOX-S algorithm in this application.
[0045] Figure 2 This is the network structure diagram of metal casting surface defect detection based on the improved YOLOX-S algorithm in this application.
[0046] Figure 3 This is the bottom-up structure diagram of the ES-PAFPN network in this application.
[0047] Figure 4 This is the structure diagram of the up-bottom part of the ES-PAFPN network in this application.
[0048] Figure 5 This is a diagram of the defect detection effect in this application example. DETAILED DESCRIPTION
[0049] The present invention will be further described below with reference to the accompanying drawings and examples.
[0050] Example:
[0051] like Figure 1-4 A metal casting surface defect detection method based on the improved YOLOX-S algorithm is shown, and the specific steps are as follows:
[0052] 1) Data acquisition: Collect several metal casting surface images in the database to construct a metal casting surface dataset;
[0053] In this example of the present invention, the image data in the database comes from surface defect images generated during the actual strip steel production process, including ten types of surface defects, namely, punching, welds, crescents, water spots, oil spots, silk spots, foreign matter, indentations, creases, and waist folds.
[0054] 2) Data preprocessing: Preprocess the data in the metal casting surface dataset and divide the processed dataset into training and test sets in proportion. The specific steps are as follows:
[0055] 2-1) performing an enhancement operation on the metal casting surface dataset, wherein the enhancement operation includes but is not limited to flipping and cropping;
[0056] 2-2) Use LabelImg software to label the enhanced dataset, construct a VOC format dataset, and divide the constructed VOC format dataset into a training set and a test set in a ratio of 8:2.
[0057] 3) Model construction: Build a metal casting surface defect detection model based on the improved YOLOX-S network; the improved YOLOX-S network shown includes a backbone network, a neck network, and a head network;
[0058] The backbone network is a feature extraction network composed of the CSPDarknet network, the neck network is a feature fusion network composed of the improved PAFPN network - ES-PAFPN network, and the head network is a classification prediction network composed of three YOLO Head networks;
[0059] The ES-PAFPN network adopts erasing and strengthening mechanism to perform indirect feature fusion.
[0060] In this example, the input image size is 640*640*3. The Focus structure changes the image channels and size to 320*320*12, making the network pay more attention to width and height information in the channel space. The Conv2D_BN_SiLU layer then increases the number of feature layer channels to 64 before feeding it into the feature extraction network.
[0061] As an embodiment of the present invention, the feature extraction network is composed of a CSPDarknet network including four Resblock body blocks connected in series for extracting features from an input image layer by layer;
[0062] Each Resblock body block is used to reduce the image size by half and double the number of channels; the last Resblock body block of the series network includes an SPP network structure used to improve the receptive field of the network;
[0063] The feature extraction network extracts three features: Feature0, Feature1, and Feature2.
[0064] In this example of the present invention, the feature extraction network extracts three features Feature0, Feature1, and Feature2, whose sizes are 20*20*1024, 40*40*512, and 80*80*256, respectively.
[0065] As an embodiment of the present invention, the feature fusion network is composed of an ES-PAFPN network, which includes two parts: bottom-up and up-bottom. The bottom-up part uses an erasing and strengthening mechanism to process the features extracted by the feature extraction network and inputs the results into the up-bottom part to further strengthen the features.
[0066] The feature fusion network ES-PAFPN inputs the three-layer features Feature0, Feature1, and Feature2 extracted by the feature extraction network; Feature0 is resized to the same size as Feature1 by the CU2 unit, and the attention mechanism CBAM is used to find the sub-feature information of Feature0 implicit in the sub-feature of Feature1. Erased feature1 and strengthened feature0 are then obtained through the erasing and enhancement mechanism. At the same time, a gating unit is introduced and the tanh activation function is used to reflect the degree of mutual influence between sub-features. According to the above method, erased feature2 and strengthened feature0 are obtained through Feature1 and Feature2.
[0067] The bottom-up part only uses the strengthening mechanism and outputs Erased feature2, Erased feature1 and Strengthened feature0; the bottom-up part outputs Erased feature2, Erased feature1 and Strengthened feature0; the bottom-up part represents:
[0068] F2 Erased =Era(Slice(F2),Slice(CU1(F1)))
[0069] F1 Erased =Str(Slice(F2),Slice(CU1(F1)))
[0070] +Era(Slice(F1),Slice(CU2(F0)))
[0071] F0 Strengthened =Str(Slice(F1),Slice(CU2(F0)))
[0072] Where F1, F2, and F3 are input features, Era represents the erasure mechanism, Str represents the strengthening mechanism, Slice represents the feature slicing operation, and CU1 and CU2 represent convolution modules.
[0073] The input of the up-bottom part is the output of the bottom-up part. The up-bottom part only strengthens the features again through the strengthening mechanism. The up-bottom part can be expressed by the following formula:
[0074] F1 Final =Str(Slice(F1 Erased ),Slice(DC1(F2 Erased )))
[0075] F0 Final =Str(Slice(F0 Strengthened ),Slice(DC2(F1 Final )))
[0076] Where, F1 Erased , F2 Erased , F0 Strengthened , F1 Fional is the input feature, Str represents the strengthening mechanism, Slice represents the feature slicing operation, DC1 and DC2 represent the convolution module;
[0077] The outputs of the ES-PAFPN are Erased feature 2, Final feature 1, and Final feature 0.
[0078] In the example of the present invention, the feature fusion network in the original YOLOX-S network uses the PAFPN network, which directly fuses the features extracted by the feature extraction network through upsampling and downsampling. This fusion method has a semantic difference problem, that is, features of different categories will affect each other. In order to more reasonably utilize the features extracted by the feature extraction network, the ES-PAFPN network uses an indirect fusion method to strengthen the features. For the features extracted by the feature extraction network, adjacent feature layers will affect each other. The indirect fusion method using the erasure and enhancement mechanism can erase the adjacent layer features implicit in the features of this layer, and strengthen the features of this layer that are of interest, avoiding the semantic difference problem of direct fusion, improving the network's detection accuracy for dense defects, and providing a technical reference for filling surface defects in metal castings.
[0079] In this example of the present invention, in order to make full use of the features extracted by the feature extraction network, the features are divided into 32 sub-channel features; the output of the ES-PAFPN is Erased feature 2, Final feature 1, and Final feature 0, whose sizes are 80*80*256, 40*40*512, and 20*20*1024, respectively.
[0080] As an embodiment of the present invention, the classification prediction network is composed of three YOLO Head networks, the YOLO Head network adopts a decoupled head structure, and the YOLO Head network includes three parts: Reg part, Obj part, and Cls part;
[0081] The Reg part is used to represent the offset of the center point of the prediction box and the width and height information of the prediction box, the Obj part is used to represent the probability that the prediction box contains an object, and the Cls part is used to represent the probability that the prediction box corresponds to a certain type of defect.
[0082] 4) Model training: Use the dataset to train a metal casting surface defect detection model based on the improved YOLOX-S algorithm. The specific steps are as follows:
[0083] 4-1) Using the transfer learning method, pre-training is performed on the training set of the VOC dataset, and then the pre-trained weights are used in this metal surface casting defect detection network;
[0084] 4-2) Input the test set data into the metal surface casting defect detection network obtained in step 4-1), and take the weight with the highest test set accuracy as the weight of the trained improved YOLOX-S network.
[0085] In the example of the present invention, the metal surface casting defect detection network is trained for a total of 300 rounds using the training set data in step 4-1), and the trained model is input into step 4-2).
[0086] 5) Defect Detection: Input the surface image of the metal casting to be inspected into the trained improved YOLOX-S network to obtain a result image containing defect categories and defect locations:
[0087] Collect the surface defect images of the strip and obtain Figure 5 The weld and punching defects shown in (a) are located in the middle and lower right corner of the picture, respectively. Figure 5 The crease defect shown in (b) is located on the right side of the picture. Figure 5 The foreign body defect shown in (c) is located on the left side of the image. Figure 5 (d) The indentation defect shown is located on the right side of the image.
[0088] Depend on Figure 5 From the detection results of (a), (b), (c) and (d), it can be seen that the metal casting surface defect detection model based on the improved YOLOX-S algorithm proposed in this application improves the network's detection accuracy for dense defects and can provide a technical reference for filling surface defects of metal castings.
[0089] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0090] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.
[0091] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0092] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0093] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered by the scope of protection of the claims of the present invention.
Claims
1. A metal casting surface defect detection method based on an improved YOLOX-S algorithm, characterized in that: The specific steps are as follows: 1) Data acquisition: Collect several metal casting surface images from the database to construct a metal casting surface dataset; 2) Data preprocessing: Preprocess the data in the metal casting surface dataset and divide the processed dataset into training and test sets in proportion; 3) Model construction: Build a metal casting surface defect detection model based on the improved YOLOX-S network; 4) Model training: Use the dataset to train a metal casting surface defect detection model based on the improved YOLOX-S algorithm; 5) Defect Detection: Input the surface image of the metal casting to be inspected into the trained improved YOLOX-S network to obtain a result map containing defect categories and defect locations; In step 3), the improved YOLOX-S network includes the backbone network, the neck network, and the head network; The backbone network is a feature extraction network composed of the CSPDarknet network, the neck network is a feature fusion network composed of the improved PAFPN network - ES-PAFPN network, and the head network is a classification prediction network composed of three YOLO Head networks; The ES-PAFPN network adopts erasing and strengthening mechanism to perform indirect feature fusion.
2. The metal casting surface defect detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that: The specific steps of data preprocessing in step 2) are: 2-1) performing an enhancement operation on the metal casting surface dataset, wherein the enhancement operation includes but is not limited to flipping and cropping; 2-2) Use LabelImg software to label the enhanced dataset, construct a VOC format dataset, and divide the constructed VOC format dataset into training and test sets in an 8:2 ratio.
3. The metal casting surface defect detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that: The feature extraction network is composed of a CSPDarknet network including four Resblock body blocks connected in series for extracting features from the input image layer by layer; Each Resblock body block is used to reduce the image size by half and double the number of channels; the last Resblock body block of the series network includes an SPP network structure used to improve the receptive field of the network; The feature extraction network extracts three features: Feature0, Feature1, and Feature2.
4. The metal casting surface defect detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that: The feature fusion network is composed of an ES-PAFPN network, which includes two parts: bottom-up and up-bottom. The bottom-up part uses an erasing and strengthening mechanism to process the features extracted by the feature extraction network and inputs the results into the up-bottom part to further strengthen the features. The feature fusion network ES-PAFPN inputs the three-layer features Feature0, Feature1, and Feature2 extracted by the feature extraction network; Feature0 is resized to the same size as Feature1 by the CU2 unit, and the attention mechanism CBAM is used to find the sub-feature information of Feature0 implicit in the sub-feature of Feature1. Erased feature1 and strengthened feature0 are then obtained through the erasing and enhancement mechanism. At the same time, a gating unit is introduced and the tanh activation function is used to reflect the degree of mutual influence between sub-features. According to the above method, erased feature2 and strengthened feature0 are obtained through Feature1 and Feature2. The bottom-up part only uses the strengthening mechanism and outputs Erased feature2, Erased feature1 and Strengthened feature0; the bottom-up part outputs Erased feature2, Erased feature1 and Strengthened feature0; the bottom-up part represents: Where F1, F2, and F3 are input features, Era represents the erasure mechanism, Str represents the strengthening mechanism, Slice represents the feature slicing operation, and CU1 and CU2 represent convolution modules. The input of the up-bottom part is the output of the bottom-up part. The up-bottom part only strengthens the features again through the strengthening mechanism. The up-bottom part can be expressed by the following formula: Where, F1 Erased , F2 Erased , F0 Strengthened , F1 Fional is the input feature, Str represents the strengthening mechanism, Slice represents the feature slicing operation, DC1 and DC2 represent the convolution module; The outputs of the ES-PAFPN are Erased feature 2, Final feature 1, and Final feature 0.
5. The metal casting surface defect detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that: The classification prediction network is composed of three YOLO Head networks. The YOLO Head network adopts a decoupled head structure. The YOLO Head network includes three parts: Reg, Obj, and Cls. The Reg part is used to represent the offset of the center point of the prediction box and the width and height information of the prediction box, the Obj part is used to represent the probability that the prediction box contains an object, and the Cls part is used to represent the probability that the prediction box corresponds to a certain type of defect.
6. The metal casting surface defect detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that: The specific method of model training in step 4) is: 4-1) Using the transfer learning method, pre-training is performed on the training set of the VOC dataset, and then the pre-trained weights are used in this metal surface casting defect detection network; 4-2) Input the test set data into the metal surface casting defect detection network obtained in step 4-1) and take the weight with the highest test set accuracy as the weight of the trained improved YOLOX-S network.
Citation Information
Patent Citations
FE-YOLO-based copper pipe surface defect detection method and device
CN114638784A