An aluminum profile surface defect detection method based on an improved YOLOv5 algorithm
By improving the YOLOv5 algorithm and optimizing the anchor frame, global attention module C3C2F, and lightweight upsampling operator CARAFE using the IOU-K-means++ algorithm, the problem of insufficient accuracy in detecting small targets on aluminum profile surfaces was solved, and more efficient defect identification was achieved.
Patent Information
- Application Number
- CN202310758415.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-26
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2043-06-26
AI Technical Summary
Existing deep learning network models have insufficient accuracy in aluminum profile surface defect detection, especially in small target detection, making it difficult to effectively identify diverse aluminum profile surface defects with large scale differences.
An improved YOLOv5 algorithm is adopted, anchor boxes are optimized through the IOU-K-means++ algorithm, and a global attention module C3C2F and a lightweight upsampling operator CARAFE are introduced to enhance the semantic information and detection capability of small targets.
It significantly improves the detection accuracy of small target defects on the surface of aluminum profiles, reduces the false negative rate, and enhances the detection effect.
Smart Images

Figure CN116958056B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of surface defect detection, and particularly relates to an aluminum profile surface defect detection method based on an improved YOLOv5 algorithm. BACKGROUND
[0002] With the rapid development of global industrialization, aluminum profiles have become the preferred material in infrastructure and industrial fields due to their low density, high plasticity, and excellent corrosion resistance, and the demand is growing. However, the surface defect problem of aluminum profiles is always a difficult problem that manufacturers need to solve. Defects such as scratches, paint bubbles, and dirty spots caused by processing technology and production equipment need to be excluded through surface quality detection to ensure product quality.
[0003] Current industrial product surface defect detection can be divided into three categories: manual detection, single mechanism recognition, and machine vision recognition. Compared with manual detection and single mechanism recognition, machine vision recognition has the advantages of high efficiency, low cost, and non-contact, and has gradually become the mainstream defect detection method. Traditional machine vision-based defect detection methods use various image processing techniques and machine learning algorithms to analyze and classify defect images, but this method is tedious and has poor robustness, and has certain limitations. With the improvement of computer computing power and the development of deep learning networks, surface defect detection is gradually shifting to deep learning-based methods. This method not only has higher accuracy and robustness, but also can process large amounts of image data more quickly. The current mainstream deep learning-based target detection algorithm can be divided into two categories: one is the two-stage algorithm such as R-CNN, Fast R-CNN, etc. This algorithm needs to generate candidate regions in advance and has high precision; the other is the one-stage algorithm such as YOLO, SSD, etc. This algorithm directly extracts features in the network for detection and is relatively fast. However, in industry, aluminum profile surface defects are diverse and have large scale differences. Existing deep learning network models have achieved good large target detection results, but still need to be improved in small target detection. SUMMARY
[0004] The purpose of the application is to solve the problems of the prior art. The application provides an aluminum profile surface defect detection method based on an improved YOLOv5 algorithm, which significantly improves the detection accuracy of small targets while maintaining the detection accuracy of large targets.
[0005] Technical scheme: An aluminum profile surface defect detection method based on an improved YOLOv5 algorithm, comprising the following steps:
[0006] S1: Obtain an aluminum profile public data set, and use the aluminum profile data set of the Guangdong Industrial Manufacturing Big Data Innovation Competition-Aluminum Profile Surface Defect Recognition;
[0007] S2: Adopting the method of horizontal flip, vertical flip and translation random combination to enhance the data of aluminum profile dataset, each defect type dataset is enhanced to 500, finally a total of 3500 aluminum profile datasets are contained;
[0008] S3: Using Labelimg tool to label the defects of the data enhanced aluminum profile image, generating yolo format data label, and dividing the obtained all datasets into training set and validation set according to 8:2;
[0009] S4: Improving YOLOv5 model, using IOU-K-means++ algorithm to cluster and optimize anchor frame in image input part; Introducing global attention module C3C2F in Backbone part to enhance the semantic information of small targets; In the Neck part, the feature map is up-sampled by the light weight up-sampling operator CARAFE, which fully retains the small target information of the up-sampled feature map;
[0010] S5: Importing the training set and validation set in S2 into the improved YOLOv5 model in S4 to detect the effect of training and validation, finally obtaining a best.pt and last.pt weight file;
[0011] S6: Finally, using the best.pt weight file obtained in S5 to infer and detect the surface defects of aluminum profile in industry.
[0012] Further: In step S1, the obtained aluminum profile dataset has seven types of defects: non-conducting, orange peel, crater, scratch, jet, paint bubble and dirty spot, and the picture size is 2560*1920.
[0013] Further: In step S4, IOU-K-means++ algorithm is used to cluster and optimize anchor frame in image input part; original YOLOv5 uses K-means algorithm to cluster anchor frame, which depends on initial clustering center, K-means++ can solve this problem, in the initial step of K-means++, only one clustering center is randomly selected, and then the remaining clustering centers are determined according to the probability of distance from cluster center, because the selection of clustering center has discreteness and globality, the clustering result is more accurate and reasonable; this method also uses IOU(Intersection over Union) instead of Euclidean distance to estimate the similarity of two objects, so that the quality of clustered anchor frame is better;
[0014] The specific steps are: first, the aluminum profile image is adaptively scaled to 640*640, then the IOU-K-means++ algorithm is used to cluster the anchor frame, and the anchor frame most suitable for the surface defects of aluminum profile is obtained;
[0015] wherein the distance formula of the IOU can be expressed as:
[0016] d(box, centroid) = 1 - IOU(box, centroid)
[0017] In the formula, IOU represents the ratio of the intersection and union of the real box and the cluster center, the higher the IOU value represents that the real box is closer to the cluster center, that is, the higher the correlation between the two;
[0018] In the Backbone part, a global attention module C3C2F is introduced to enhance the semantic information of small targets, and the global attention module C3C2F is obtained by replacing the BottleNeck in the C3 module with a convolution modulation module ConvMod;
[0019] In the Neck part, a light-weight upsampling operator CARAFE is used for feature map upsampling, which fully retains the small target information of the upsampled feature map, and a light-weight upsampling operator CARAFE is used to replace the nearest neighbor interpolation upsampling method in the original YOLOv5 for feature map upsampling at the 11th layer and the 15th layer.
[0020] Further: the convolution modulation module ConvMod has two branches and a residual edge, the first branch of ConvMod uses 1x1 convolution to retain the original feature map information, the second branch first normalizes the input features with LayerNorm to ensure the stability of the data feature distribution, then uses 1x1 convolution and activation function GELU to ensure that the feature map size does not change under the premise of greatly increasing the non-linear characteristics, and finally uses an 11x11 deep convolution to reduce the parameter amount while expanding the receptive field; the second branch is used as a weight to modulate the first branch to make full use of the context information of the image to make the model more focused on the target to be detected and reduce the interference of irrelevant background.
[0021] Further: the structure of the global attention module C3C2F is: changing the BottleNeck in C3 to ConvMod to construct the global attention module C3C2F, the C3C2F module can model the global context information, not only reducing the parameter amount of the model, but also enhancing the semantic information of small target defects on the surface of aluminum profiles and suppressing background and noise.
[0022] Further: the structure of the light-weight upsampling operator CARAFE includes two parts: an upsampling kernel prediction module and a feature recombination module, first input the defect feature maps of the surface of aluminum profiles output by the 10th layer and the 14th layer into the upsampling kernel prediction module and the feature recombination module.
[0023] Further: in the upsampling kernel prediction module, the upsampling ratio is sigma, first compress the channel number to C mThen, the content encoding is implemented by a convolution operation with a convolution of size k encoder ×k encoder Finally, the spatial dimension is unfolded and the kernel normalization is performed, so that the convolution kernel weight sum is 1.
[0024] Further, in the feature reorganization module, a k up ×k up Region centered on each position of the feature map and the reorganization kernel W l′ of the up-sampling prediction module are taken to perform dot product, and finally the up-sampled feature map is obtained; the lightweight up-sampling operator CARAFE expands the receptive field, adapts to the input content and fully retains the small target information of the up-sampled feature map.
[0025] Further, in the step S5, the training weight parameter weights is set as yolov5s.pt, epochs is set as 300, batch-size is set as 32, input image size imgsz is set as 640, and the hyperparameter hyp adopts the hyp.scratch-low.yaml file.
[0026] Further, in the step S6, the inference program is run, the image to be detected is input, the weight weights is set as best.pt, and finally the detected defect image is obtained.
[0027] Beneficial effects: firstly, the IOU-K-means++ algorithm is used to replace the K-means algorithm to cluster anchor frames, so that the anchor frame most suitable for the surface defects of the aluminum profile is obtained, and the quality of the small target anchor frame is improved; secondly, the global attention module C3C2F is proposed, and the backbone layer is introduced, so that the semantic information and global perception ability of the small target are enhanced while the parameter amount is reduced; finally, the nearest neighbor interpolation up-sampling mode of the neck is replaced by the lightweight up-sampling operator CARAFE, so that the small target information of the up-sampled feature map is fully retained. Experiments prove that the present application effectively improves the small defect missing detection problem of the aluminum profile surface in the industry, and improves the aluminum profile surface defect detection precision. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 is the aluminum profile surface defect detection framework of the improved YOLOv5 algorithm of the present application;
[0029] Figure 2 is a structure diagram of the convolution modulation module ConvMod of the present application;
[0030] Figure 3 is a structure diagram of the global attention module C3C2F of the present application;
[0031] Figure 4 is a structure diagram of the lightweight up-sampling operator CARAFE of the present application;
[0032] Figure 5 The precision-recall curve comparison chart of the improved YOLOv5 algorithm of the application and the original YOLOv5;
[0033] Figure 6 The detection result comparison chart of the improved YOLOv5 algorithm of the application and the original YOLOv5 for small target defect blister and dirty point. DETAILED DESCRIPTION
[0034] The technical solutions in the embodiments of the application will be described clearly and completely below, so that those skilled in the art can better understand the advantages and features of the application, and the protection scope of the application can be defined more clearly. The embodiments described in the application are only some of the embodiments of the application, not all the embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor belong to the protection scope of the application.
[0035] EMBODIMENT
[0036] The application provides an aluminum profile surface defect detection method based on an improved YOLOv5 algorithm, which combines an IOU-K-means++ algorithm, a global attention module C3C2F and a lightweight up-sampling operator CARAFE, realizes clustering optimization of anchor frames and enhancement of small target semantic information, and improves the detection precision of small target defects on the surface of aluminum profiles. The specific steps are as follows:
[0037] S1: Obtain an aluminum profile public data set, go to the Ali Cloud Tianchi competition platform, and download the aluminum profile data set of the 2018 Guangdong Industrial Manufacturing Big Data Innovation Competition-Aluminum Profile Surface Defect Recognition. The obtained aluminum profile data set has seven types of defects: non-conductive, orange peel, crater, scratch, jet flow, blister and dirty point, and the picture size is 2560*1920.
[0038] S2: The aluminum profile data set is subjected to data enhancement by adopting a method of horizontal flip, vertical flip and random translation combination, each defect type data set is enhanced to 500, and finally a total of 3500 aluminum profile data sets are included.
[0039] S3: The Labelimg tool is used for defect labeling of the aluminum profile image after data enhancement, yolo format data labels are generated, and all data sets obtained are divided into training sets and validation sets according to 8:2.
[0040] S4: Improve the YOLOv5 model, use the IOU-K-means++ algorithm to cluster and optimize the anchor frame in the image input part; introduce the global attention module C3C2F in the Backbone part to enhance the semantic information of small targets; in the Neck part, use the lightweight up-sampling operator CARAFE to up-sample the feature map, and fully retain the small target information of the up-sampled feature map.
[0041] S5: Import the training set and validation set in S2 into the improved YOLOv5 model in S4 to detect the effect of training and validation, and finally get a best.pt and last.pt weight file. The training parameter weights is set to yolov5s.pt, epochs is set to 300, batch-size is set to 32, input image size imgsz is set to 640, and hyperparameter hyp adopts hyp.scratch-low.yaml file.
[0042] S6: Finally, use the best.pt weight file obtained in S5 to infer and detect the surface defects of aluminum profiles in industry. That is, run the inference program detect.py, input the aluminum profile surface defect image for detection, and weights is set to best.pt.
[0043] In the above step S4, the IOU-K-means++ algorithm is used to cluster and optimize the anchor frame in the image input part. The original YOLOv5 uses the K-means algorithm to cluster the anchor frame, which depends on the initial clustering center. K-means++ can solve this problem. In the initial step of K-means++, only one clustering center is randomly selected, and then the remaining clustering centers are determined in order according to the probability of distance from the cluster center. Because the selection of clustering center has discreteness and globality, the clustering result is more accurate and reasonable. In this paper, IOU (Intersection over Union) is used instead of Euclidean distance to estimate the similarity of two objects, so that the quality of the clustered anchor frame is better. The specific steps are as follows: first, the aluminum profile image is adaptively scaled to 640*640, then the IOU-K-means++ algorithm is used to cluster the anchor frame, and the anchor frame that best fits the aluminum profile surface defect is obtained.
[0044] Wherein, the distance formula of the above IOU can be expressed as:
[0045] d(box, centroid) = 1-IOU(box, centroid)
[0046] In the formula, IOU represents the ratio of the intersection and union of the real frame and the clustering center. The higher the IOU value represents the closer the real frame and the clustering center, that is, the higher the correlation between the two.
[0047] A global attention module C3C2F is introduced in the Backbone part to enhance the semantic information of small targets. The C3C2F module is obtained by replacing the BottleNeck in the C3 module with a ConvMod. Figure 2 As shown in the structural diagram of the ConvMod module in the middle, the ConvMod module includes two branches. The first branch of the ConvMod uses a 1x1 convolution to retain the original feature map information, and the second branch first normalizes the input features with LayerNorm to ensure the stability of the data feature distribution, then uses a 1x1 convolution and an activation function GELU to greatly increase the nonlinearity while ensuring the size of the feature map, and finally uses an 11x11 deep convolution to expand the receptive field while reducing the parameter amount. The second branch is used as a weight to modulate the first branch to make full use of the context information of the image to make the model more focused on the target to be detected and reduce the interference of irrelevant background. As shown in Figure 3 As shown in the structural diagram of the global attention module C3C2F, the BottleNeck in the C3 is replaced with the ConvMod to construct the global attention module C3C2F. The C3C2F module can model the global context information, not only reducing the parameter amount of the model, but also enhancing the semantic information of small target defects on the surface of aluminum profiles and suppressing background and noise.
[0048] In the Neck part, a light-weight upsampling operator CARAFE is used for feature map upsampling to fully retain the small target information of the upsampled feature map. As shown in Figure 1 As shown in the neck network structure in the middle, a light-weight upsampling operator CARAFE is used to replace the nearest neighbor interpolation upsampling method in the original YOLOv5 for feature map upsampling at the 11th layer and the 15th layer. As shown in Figure 4 As shown in the structural diagram of the light-weight upsampling operator CARAFE, it includes two parts: an upsampling kernel prediction module and a feature recombination module. First, the defect feature maps output by the 10th layer and the 14th layer of the aluminum profile surface are input into the upsampling kernel prediction module and the feature recombination module, respectively. In the upsampling kernel prediction module, the upsampling rate is σ, the channel number is first compressed to C m , then a convolution operation is performed through a convolution with a size of k encoder ×k encoder to realize content encoding, and finally the kernel is normalized in the spatial dimension to make the convolution kernel weight sum equal to 1. In the feature recombination module, the k up ×k up region centered at each position of the feature map and the recombination kernel W l′ of the upsampling prediction module are taken to perform dot product, and finally the upsampled feature map is obtained. The light-weight upsampling operator CARAFE expands the receptive field, adapts to the input content, and fully retains the small target information of the upsampled feature map.
[0049] Figure 5 For the Precision-recall curve diagram of the original YOLOv5 model and the improved YOLOv5 model in step S3, it is found from the figure that the average precision of non-conducting, orange peel, crater, scratch, spray flow, paint bubble and dirty spot is increased by 3.4%, 0.1%, 0%, 2.4%, 0.1%, 5.2% and 12.4% respectively. Among them, the detection accuracy of small target defects such as paint bubble and dirty spot is significantly improved, which verifies the effectiveness of the improved model for small target defects on the surface of aluminum profile. Figure 6 For the comparison chart of the detection results of small target defects such as paint bubble and dirty spot by the improved YOLOv5 algorithm and the original YOLOv5 algorithm, it is found that the improved model effectively reduces the missed detection problem of small target defects by the original YOLOv5 model, and improves the confidence.
Claims
1. An aluminum profile surface defect detection method based on an improved YOLOv5 algorithm, characterized by: The method comprises the following steps: S1: obtaining an aluminum profile public data set, adopting an aluminum profile data set of an aluminum profile surface defect identification of a Guangdong industrial manufacturing big data innovation competition; S2: adopting a method of random combination of horizontal flipping, vertical flipping and translation to perform data enhancement on the aluminum profile data set, each defect type data set being enhanced to 500 images, and finally a total of 3500 aluminum profile data sets being contained; S3: using a Labelimg tool to perform defect labeling on the aluminum profile images after data enhancement, generating a yolo format data label, and dividing all data sets into a training set and a verification set according to 8:2; S4: improving a YOLOv5 model, adopting an IOU-K-means++ algorithm to cluster and optimize anchor frames in the image input part; introducing a global attention module C3C2F in the Backbone part to enhance the semantic information of small targets; and performing feature map upsampling through a lightweight upsampling operator CARAFE in the Neck part to fully retain the small target information of the upsampled feature map; S5: importing the training set and the verification set in S2 into the improved YOLOv5 model in S4 to perform effect detection while training and verifying, and finally obtaining a best.pt and last.pt weight file; S6: finally, using the best.pt weight file obtained in S5 to perform inference detection on the surface defects of the aluminum profile in the industry; In the step S1, the aluminum profile data set obtained has seven types of defects: non-conducting, orange peel, crater, scratch, jet, paint bubble and dirty spot, and the picture size is 2560*1920; In the step S4, the IOU-K-means++ algorithm is adopted to cluster and optimize anchor frames in the image input part; The specific steps are as follows: first, the aluminum profile image is adaptively scaled to 640*640, and then the IOU-K-means++ algorithm is used to cluster anchor frames to obtain anchor frames most suitable for aluminum profile surface defects; The distance formula of the above-mentioned IOU can be expressed as: d(box,centroid)=1-IOU(box,centroid) In the formula, IOU represents the ratio of the intersection and union of the real frame and the cluster center, and the higher the IOU value represents that the real frame is closer to the cluster center, that is, the higher the correlation between the two; In the Backbone part, a global attention module C3C2F is introduced to enhance the semantic information of small targets, and the global attention module C3C2F is obtained by replacing the BottleNeck in the C3 module with a convolution modulation module ConvMod; In the Neck part, a lightweight upsampling operator CARAFE is used to perform feature map upsampling, fully retaining the small target information of the upsampled feature map, and the lightweight upsampling operator CARAFE is used to replace the nearest neighbor interpolation upsampling method in the original YOLOv5 to perform feature map upsampling at the 11th layer and the 15th layer. The convolution modulation module ConvMod includes two branches, the first branch of ConvMod uses a 1*1 convolution to retain the original feature map information, the second branch first normalizes the input features using LayerNorm to ensure the stability of the data feature distribution, then uses a 1*1 convolution and an activation function GELU to greatly increase the non-linear characteristics under the premise of ensuring the size of the feature map, and finally uses an 11*11 deep convolution to reduce the parameter amount while expanding the receptive field; the second branch is used as a weight to modulate the first branch to make full use of the context information of the image to make the model more focused on the target to be detected and reduce the interference of irrelevant background; The structure of the global attention module C3C2F is that: the BottleNeck in C3 is changed to ConvMod, the global attention module C3C2F is constructed, and the C3C2F module can model the global context information, which not only reduces the parameter amount of the model, but also enhances the semantic information of the small target defects on the surface of the aluminum profile and suppresses the background and noise; The structure of the lightweight upsampling operator CARAFE includes two parts: an upsampling kernel prediction module and a feature recombination module, first, the aluminum profile surface defect feature maps output by the 10th layer and the 14th layer are respectively input into the upsampling kernel prediction module and the feature recombination module; In the up-sampling kernel prediction module, the up-sampling rate is σ, the channel number is compressed to C m firstly, then the content is encoded through convolution operation with a convolution of size k encoder ×k encoder , and finally, the spatial dimension is expanded and the kernel is normalized, so that the convolution kernel weight sum is 1; In the feature reorganization module, k up ×k up regions centered on each position of the feature map and the reorganization kernel W of the up-sampling prediction module are taken out l′ are multiplied, and finally the up-sampled feature map is obtained; the lightweight up-sampling operator CARAFE expands the receptive field, adapts to the input content, and fully retains the small target information of the up-sampled feature map; In the step S5, the training weight parameter weights is set as yolov5s.pt, epochs is set as 300, batch-size is set as 32, input image size imgsz is set as 640, and the hyperparameter hyp adopts the hyp.scratch-low.yaml file; In the step S6, the inference detection program is run, the image to be detected is input, the weight weights is set as best.pt, and finally the detected defect image is obtained.
Citation Information
Patent Citations
Aluminum profile surface defect visual detection method based on improved yolov3
CN112991271A