Improved aluminum profile surface defect detection method
By improving the YOLOv5 model, adding a small object detection layer and CA attention mechanism, the problem of low detection accuracy of small object detection on the surface of aluminum profiles is solved, more efficient and accurate defect detection is achieved, and product quality is improved.
Patent Information
- Application Number
- CN202411421317.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-02-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, the small target detection accuracy of aluminum profile surface is not high, making it difficult to meet the modern industry's demand for efficient and accurate inspection.
Improve the detection method of the YOLOv5 model, add a small object detection layer, and add a CA attention mechanism to the model, and improve the loss function to solve the problem of mismatch angles between the prediction box and the real box.
It significantly improves the detection accuracy of small target defects on the surface of aluminum profiles, reduces waste and losses caused by missed inspection or missed inspection, and improves the overall quality of the product.
Smart Images

Figure CN119417768A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of aluminum profile surface defect detection, and in particular to an improved aluminum profile surface defect detection method. Background Art
[0002] With the continuous advancement of the global industrialization process, aluminum profiles have been widely recognized and used by the public. It has important applications in the fields of construction, automobile transportation and high-end equipment manufacturing. Due to the influence of various factors in the manufacturing process, various defects often appear on the surface of aluminum profiles, such as non-conductivity, jets, scratches, etc. These defects not only affect the appearance of aluminum profiles, but also lead to problems such as reduced product performance and shortened service life. Therefore, the detection of surface defects of aluminum profiles is an important link to ensure the quality of aluminum profiles.
[0003] Traditional aluminum profile surface defect detection methods mainly include eddy current detection, ultrasonic guided wave detection and infrared detection. These methods have limitations such as high recognition cost, complex equipment, and difficulty in visualizing the defect recognition process, which makes it difficult to meet the needs of modern industry for efficient and accurate detection. With the continuous development of machine vision technology, as a non-contact online automatic detection technology, it has the characteristics of non-contact, high safety, high recognition efficiency and long working time, and has gradually become an effective means to achieve accurate and rapid recognition of aluminum profile surface defects.
[0004] YOLO (You On ly Look Once) is a target detection algorithm that is efficient, accurate and real-time. Since the introduction of YOLOv1, it has been continuously improved in YOLOv2, YOLOv3, YOLOv4 and other versions, and its speed and accuracy have been significantly improved. YOLOv5 has further improved the accuracy of detection while maintaining high efficiency. Although YOLOv5 has achieved good results in large target detection, it still needs to be improved in small target detection. Summary of the invention
[0005] The purpose of the present invention is to solve the problem of low small target detection accuracy in the prior art and to propose an improved aluminum profile surface defect detection method.
[0006] In order to achieve the above object, the present invention adopts the following technical solution: an improved aluminum profile surface defect detection method, comprising the following steps:
[0007] Step S1, obtaining a data set of surface defects of aluminum profiles through the network;
[0008] Step S2, cleaning, labeling, and enhancing the acquired data set, and dividing the processed data set;
[0009] Step S3, determining the indicators for evaluating the model performance to evaluate the performance of the model in the detection task;
[0010] Step S4, improving the detection method of the YOLOv5 model and adding a small target detection layer to the model;
[0011] Step S5, adding CA attention mechanism to the YOLOv5 model to improve the performance of the model;
[0012] Step S6, improving the loss function in the YOLOv5 model to solve the problem of mismatching angles between the predicted box and the real box;
[0013] Step S7, training the improved YOLOv5 model;
[0014] Step S8, performing defect detection by improving the YOLOv5 model.
[0015] Furthermore, in step S1, the following sub-steps are also included:
[0016] S1-1, obtained the preliminary open source data set from the 2018 Guangdong Industrial Intelligent Manufacturing Big Data Innovation Competition-Intelligent Algorithm Competition "Aluminum Profile Surface Defect Recognition" through the Internet;
[0017] S1-2, this dataset divides aluminum profile surface defects into 10 categories: dents (N1), non-conductive (N2), scratches (N3), orange peel (N4), bottom leakage (N5), bruises (N6), pits (N7), convex powder (N8), coating cracks (N9) and dirty spots (N10);
[0018] S1-3, this dataset includes 1018 defect-free images and 1228 labeled images with defects, including 250 single-defect images and 978 multiple-defect images, with a resolution of 2560×1920.
[0019] Furthermore, in step S2, the following sub-steps are also included:
[0020] S2-1, correct or delete the noise, blur or distortion in the image;
[0021] S2-2, manually or automatically annotate the datasets that do not provide detailed annotation information;
[0022] S2-3, enhance the original image by rotating, scaling, and flipping;
[0023] S2-4, divide the labeled data set into three parts: training set, validation set and test set in the ratio of 8:1:1.
[0024] Furthermore, in step S3, the following sub-steps are also included:
[0025] S3-1, model evaluation indicators include precision P, recall R, F 1 Score and mean average precision mAP;
[0026] S3-2, calculate the precision P by the following formula:
[0027]
[0028] Among them, N TP Indicates the number of positive samples correctly identified as positive samples; N FP Indicates the number of negative samples that are mistakenly identified as positive samples;
[0029] S3-3, calculate the recall rate R by the following formula:
[0030]
[0031] Among them, N FN Indicates the number of samples marked as positive and identified as negative samples;
[0032] S3-4, calculate F by the following formula 1 Fraction:
[0033]
[0034] Among them, F 1 The score is the harmonic mean of precision P and recall R:
[0035] S3-5, calculate the mean average precision mAP by the following formula:
[0036]
[0037] Where m represents the total number of all defective samples.
[0038] Furthermore, in step S4, the following sub-steps are also included:
[0039] S4-1, add new feature detection layer detection in YOLOv5 model;
[0040] S4-2, the formula for judging the detection layer of the improved YOLOv5 model is as follows:
[0041]
[0042] Among them, Q is the size of the target in the image, the detection feature map size of the new detection layer is 152*152, the detection feature map size of the large detection layer is 76*76, the detection feature map size of the medium detection layer is 38*38, and the detection feature map size of the small detection layer is 19*19.
[0043] Furthermore, in step S5, the following sub-steps are also included:
[0044] S5-1, given an intermediate feature tensor X:
[0045] X=[x 1 , x 2 , …, x c ]∈R H*W*C
[0046] Among them, H is the height of the feature map, W is the width of the feature map, and C is the number of channels;
[0047] S5-2, after transformation, outputs a feature tensor Y of the same size:
[0048] Y=[y 1 ,y 2 , …, y c ]∈R H*W*C
[0049] Among them, Y is the feature tensor recalibrated by the channel attention mechanism.
[0050] Furthermore, in step S6, the following sub-steps are also included:
[0051] S6-1, introduce SI oU loss as the positioning loss function of bounding box regression;
[0052] S6-2, SIoU loss function consists of four loss functions, namely: angle loss, shape loss, distance loss and I oU cost;
[0053] S6-3, SI oU l oss loss function formula is as follows:
[0054]
[0055] Among them, Λ is the angle loss, Δ is the distance loss considering the angle loss, and Ω is the shape loss.
[0056] Furthermore, in step S7, the following sub-steps are also included:
[0057] S7-1, set training parameters in the configuration file of improved YOLOv5;
[0058] S7-2, start training the model using the provided training script and the prepared dataset;
[0059] S7-3, after training is completed, use the test set to evaluate the performance of the model.
[0060] Furthermore, in step S8, the following sub-steps are also included:
[0061] S8-1, load the trained improved YOLOv5 model weight file and configuration file;
[0062] S8-2, inputting the image that needs to detect defects into the model;
[0063] S8-3, calling the detection function of the improved YOLOv5 model to perform defect detection on the input image.
[0064] The beneficial effects brought about by the technical solution provided by the present invention include at least:
[0065] The present invention obtains a data set of surface defects of aluminum profiles through a network; cleans, annotates, and enhances the obtained data set, and divides the processed data set; determines an index for evaluating model performance to evaluate the performance of the model in the detection task; improves the detection method of the YOLOv5 model, and adds a small target detection layer to the model; adds a CA attention mechanism to the YOLOv5 model to improve the performance of the model; improves the loss function in the YOLOv5 model to solve the problem of mismatched angles between the predicted frame and the real frame; trains the improved YOLOv5 model; and performs defect detection on the improved YOLOv5 model. The method of the present invention can significantly improve the detection accuracy of small target defects on the surface of aluminum profiles, reduce waste and loss caused by missed detection or false detection, and improve the overall quality of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0067] Figure 1 A flow chart of a method provided by an embodiment of the present invention;
[0068] Figure 2 A structural diagram of adding a detection layer to YOLOv5 provided in an embodiment of the present invention;
[0069] Figure 3 A structural diagram of the attention mechanism provided by the embodiment of the present invention;
[0070] Figure 4 This is a diagram of the detection results provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0071] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of an improved aluminum profile surface defect detection method proposed by the present invention, its specific implementation method, structure, characteristics and effects, in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures, or characteristics in one or more embodiments may be combined in any suitable form.
[0072] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0073] The following examples are for illustrative purposes only and are not intended to limit the scope of the present invention.
[0074] The specific scheme of an improved aluminum profile surface defect detection method provided by the present invention is described in detail below with reference to the accompanying drawings.
[0075] Example
[0076] See also Figure 1-4 , which shows a method flow chart of an improved aluminum profile surface defect detection method provided by an embodiment of the present invention, the method comprising the following steps:
[0077] Step S1, obtaining a data set of surface defects of aluminum profiles through the network;
[0078] Wherein step S1 also includes the following sub-steps:
[0079] S1-1, obtained the preliminary open source data set from the 2018 Guangdong Industrial Intelligent Manufacturing Big Data Innovation Competition-Intelligent Algorithm Competition "Aluminum Profile Surface Defect Recognition" through the Internet;
[0080] S1-2, this dataset divides aluminum profile surface defects into 10 categories: dents (N1), non-conductive (N2), scratches (N3), orange peel (N4), bottom leakage (N5), bruises (N6), pits (N7), convex powder (N8), coating cracks (N9) and dirty spots (N10);
[0081] S1-3, this dataset includes 1018 defect-free images and 1228 labeled images with defects, including 250 single-defect images and 978 multiple-defect images, with a resolution of 2560×1920.
[0082] Step S2: cleaning, labeling, and enhancing the acquired data set, and dividing the processed data set;
[0083] Wherein step S2 also includes the following sub-steps:
[0084] S2-1, correct or delete the noise, blur or distortion in the image;
[0085] S2-2, manually or automatically annotate the datasets that do not provide detailed annotation information;
[0086] S2-3, enhance the original image by rotating, scaling, and flipping;
[0087] S2-4, divide the labeled data set into three parts: training set, validation set and test set in the ratio of 8:1:1.
[0088] Step S3: determining the indicators for evaluating the model performance to evaluate the performance of the model in the detection task;
[0089] Wherein step S3 also includes the following sub-steps:
[0090] S3-1, model evaluation indicators include precision P, recall R, F 1 Score and mean average precision mAP;
[0091] S3-2, calculate the precision P by the following formula:
[0092]
[0093] Among them, N TP Indicates the number of positive samples correctly identified as positive samples; N FP Indicates the number of negative samples that are mistakenly identified as positive samples;
[0094] S3-3, calculate the recall rate R by the following formula:
[0095]
[0096] Among them, N FN Indicates the number of samples marked as positive and identified as negative samples;
[0097] S3-4, calculate F by the following formula 1 Fraction:
[0098]
[0099] Among them, F 1 The score is the harmonic mean of precision P and recall R:
[0100] S3-5, calculate the mean average precision mAP by the following formula:
[0101]
[0102] Where m represents the total number of all defective samples.
[0103] See also Figure 2 , step S4, improving the detection method of the YOLOv5 model and adding a small target detection layer to the model;
[0104] Wherein step S4 also includes the following sub-steps:
[0105] S4-1, add new feature detection layer detection in YOLOv5 model;
[0106] S4-2, the formula for judging the detection layer of the improved YOLOv5 model is as follows:
[0107]
[0108] Among them, Q is the size of the target in the image, the detection feature map size of the new detection layer is 152*152, the detection feature map size of the large detection layer is 76*76, the detection feature map size of the medium detection layer is 38*38, and the detection feature map size of the small detection layer is 19*19.
[0109] See also Figure 3 , step S5, adding CA attention mechanism to the YOLOv5 model to improve the performance of the model;
[0110] Wherein, in step S5, the following sub-steps are also included:
[0111] S5-1, given an intermediate feature tensor X:
[0112] X=[x 1 , x 2 , …, x c ]∈R H*W*C
[0113] Among them, H is the height of the feature map, W is the width of the feature map, and C is the number of channels;
[0114] S5-2, after transformation, outputs a feature tensor Y of the same size:
[0115] Y=[y 1 ,y 2 , …, y c ]∈R H*W*C
[0116] Among them, Y is the feature tensor recalibrated by the channel attention mechanism.
[0117] Step S6, improving the loss function in the YOLOv5 model to solve the problem of mismatching angles between the predicted box and the true box;
[0118] Wherein, in step S6, the following sub-steps are also included:
[0119] S6-1, introduce SI oU loss as the positioning loss function of bounding box regression;
[0120] S6-2, SIoU loss function consists of four loss functions, namely: angle loss, shape loss, distance loss and I oU cost;
[0121] S6-3, SI oU l oss loss function formula is as follows:
[0122]
[0123] Among them, Λ is the angle loss, Δ is the distance loss considering the angle loss, and Ω is the shape loss.
[0124] Step S7, performing defect detection by improving the YOLOv5 model;
[0125] Wherein, in step S7, the following sub-steps are also included:
[0126] S7-1, set training parameters in the configuration file of improved YOLOv5;
[0127] S7-2, start training the model using the provided training script and the prepared dataset;
[0128] S7-3, after training is completed, use the test set to evaluate the performance of the model.
[0129] See also Figure 4 , step S8, training the improved YOLOv5 model;
[0130] Wherein, in step S8, the following sub-steps are also included:
[0131] S8-1, load the trained improved YOLOv5 model weight file and configuration file;
[0132] S8-2, inputting the image that needs to detect defects into the model;
[0133] S8-3, calling the detection function of the improved YOLOv5 model to perform defect detection on the input image.
[0134] In this way, an improved aluminum profile surface defect detection method can improve the detection accuracy of small target defects on the aluminum profile surface, reduce waste and loss, and improve the overall quality of the product.
[0135] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. An improved aluminum profile surface defect detection method, characterized in that: The method includes: Step S1, obtaining a data set of surface defects of aluminum profiles through the network; Step S2, cleaning, labeling, and enhancing the acquired data set, and dividing the processed data set; Step S3, determining the indicators for evaluating the model performance to evaluate the performance of the model in the detection task; Step S4, improving the detection method of the YOLOv5 model and adding a small target detection layer to the model; Step S5, adding CA attention mechanism to the YOLOv5 model to improve the performance of the model; Step S6, improving the loss function in the YOLOv5 model to solve the problem of mismatching angles between the predicted box and the real box; Step S7, training the improved YOLOv5 model; Step S8, performing defect detection by improving the YOLOv5 model.
2. An improved aluminum profile surface defect detection method as claimed in claim 1, characterized in that: Wherein step S1 also includes the following sub-steps: S1-1, obtained the preliminary open source data set from the 2018 Guangdong Industrial Intelligent Manufacturing Big Data Innovation Competition-Intelligent Algorithm Competition "Aluminum Profile Surface Defect Recognition" through the Internet; S1-2, this dataset divides aluminum profile surface defects into 10 categories: dents (N1), non-conductive (N2), scratches (N3), orange peel (N4), bottom leakage (N5), bruises (N6), pits (N7), convex powder (N8), coating cracks (N9) and dirty spots (N10); S1-3, this dataset includes 1018 defect-free images and 1228 labeled images with defects, including 250 single-defect images and 978 multiple-defect images, with a resolution of 2560×1920.
3. The improved aluminum profile surface defect detection method according to claim 1, characterized in that: Wherein step S2 also includes the following sub-steps: S2-1, correct or delete the noise, blur or distortion in the image; S2-2, manually or automatically annotate the datasets that do not provide detailed annotation information; S2-3, enhance the original image by rotating, scaling, and flipping; S2-4, divide the labeled data set into three parts: training set, validation set and test set in the ratio of 8:1:
1.
4. The improved aluminum profile surface defect detection method according to claim 1, characterized in that: Wherein step S3 also includes the following sub-steps: S3-1, model evaluation indicators include precision P, recall R, F1 score and average precision mAP; S3-2, calculate the precision P by the following formula: Among them, N TP Indicates the number of positive samples correctly identified as positive samples; N FP Indicates the number of negative samples that are mistakenly identified as positive samples; S3-3, calculate the recall rate R by the following formula: Among them, N FN Indicates the number of samples marked as positive and identified as negative samples; S3-4, calculate the F1 score by the following formula: Among them, the F1 score is the harmonic mean of precision P and recall R: S3-5, calculate the mean average precision mAP by the following formula: Where m represents the total number of all defective samples.
5. The improved aluminum profile surface defect detection method according to claim 1, characterized in that: Wherein step S4 also includes the following sub-steps: S4-1, add new feature detection layer detection in YOLOv5 model; S4-2, the formula for judging the detection layer of the improved YOLOv5 model is as follows: Among them, Q is the size of the target in the image, the detection feature map size of the new detection layer is 152*152, the detection feature map size of the large detection layer is 76*76, the detection feature map size of the medium detection layer is 38*38, and the detection feature map size of the small detection layer is 19*19.
6. The improved aluminum profile surface defect detection method according to claim 1, characterized in that: Wherein, in step S5, the following sub-steps are also included: S5-1, given an intermediate feature tensor X: X=[x1,x2,…,x c ]∈R H*W*C Among them, H is the height of the feature map, W is the width of the feature map, and C is the number of channels; S5-2, after transformation, outputs a feature tensor Y of the same size: Y=[y1,y2,…,y c ]∈R H*W*C Among them, Y is the feature tensor recalibrated by the channel attention mechanism.
7. An improved aluminum profile surface defect detection method as claimed in claim 1, characterized in that: Wherein, in step S6, the following sub-steps are also included: S6-1, introduce SIoU loss as the positioning loss function of bounding box regression; S6-2, SIoU loss function consists of four loss functions: angle loss, shape loss, distance loss and IoU cost; S6-3, SIoU loss loss function formula is as follows: Among them, Λ is the angle loss, Δ is the distance loss considering the angle loss, and Ω is the shape loss.
8. An improved aluminum profile surface defect detection method as claimed in claim 1, characterized in that: Wherein, in step S7, the following sub-steps are also included: S7-1, set training parameters in the configuration file of improved YOLOv5; S7-2, start training the model using the provided training script and the prepared dataset; S7-3, after training is completed, use the test set to evaluate the performance of the model.
9. An improved aluminum profile surface defect detection method as claimed in claim 1, characterized in that: Wherein, in step S8, the following sub-steps are also included: S8-1, load the trained improved YOLOv5 model weight file and configuration file; S8-2, inputting the image that needs to detect defects into the model; S8-3, calling the detection function of the improved YOLOv5 model to perform defect detection on the input image.
Citation Information
Patent Citations
Steel surface defect detection method based on improved YOLO model
CN116740051A
Steel surface defect detection method based on improved YOLOv5
CN117036244A
Steel surface defect detection method based on improved YOLOv7
CN117237611A
Improved aluminum profile surface defect detection method
CN117252806A
Target detection method based on improved YOLOv5s network model
CN117372684A