Aluminum surface real-time defect detection method and system based on improved YOLOv5

By improving the YOLOv5 network structure and combining the Ghost network, joint attention mechanism, and depthwise separable convolution, the real-time and accuracy issues in aluminum surface defect detection were solved, achieving efficient aluminum surface defect detection.

CN116012372BActive Publication Date: 2026-01-23CHANGSHA UNIVERSITY OF SCIENCE AND TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310174707.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-28
Publication Date
2026-01-23
Estimated Expiration
2043-02-28

AI Technical Summary

Technical Problem

Existing technologies for detecting surface defects in aluminum materials suffer from problems such as low real-time performance, insufficient detection accuracy, and low training efficiency. In particular, the need to collect and construct datasets for aluminum surface defects is a labor-intensive process, and insufficient data can lead to overfitting, which affects detection accuracy.

Method used

An improved YOLOv5 network structure was adopted, introducing a ghost network, a joint attention mechanism, and a depthwise separable convolution. Combined with data augmentation techniques such as paste, Gaussian blur, and Mosaic data augmentation, reinforcement transfer learning was performed, the model was optimized, and it was deployed to hardware devices for detection.

Benefits of technology

It improves the real-time performance and accuracy of detection, solves the problem of insufficient dataset size, enables lightweight model training, speeds up training, and improves detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116012372B_ABST
    Figure CN116012372B_ABST
Patent Text Reader

Abstract

The application discloses an aluminum surface real-time defect detection method and system based on an improved YOLOv5, and comprises the following steps: acquiring various aluminum material surface defect pictures, performing data enhancement picture preprocessing, and establishing a data set; inputting the preprocessed data set into an improved YOLOv5 network structure of a ghost network, a joint attention mechanism and a depth separable convolution, performing reinforcement migration training, and obtaining an optimization model; and deploying the optimization model on a hardware device to perform real-time detection of aluminum material surface defects. The application solves the problems of low real-time performance, low detection precision and low training efficiency of aluminum material surface defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of metal defect detection, and particularly relates to an aluminum surface real-time defect detection method and system based on improved YOLOv5. BACKGROUND

[0002] Aluminum profiles have become an important basic material in the fields of buildings, vehicles, ships, houses, etc. due to their good heat conductivity and moisture resistance. With the rapid development of related industries, the demand for high-quality aluminum profiles is also increasing. Therefore, aluminum profile surface defect detection is very meaningful, and aluminum profile surface defects directly affect the quality of products. Traditional manual visual inspection cannot guarantee the accuracy of the detection results and the efficiency of the detection process, because manual processing will cause a series of problems such as low efficiency and physiological fatigue of the human body. In order to solve these problems, some scholars have applied machine learning methods to the identification of industrial defects. Yu et al. used SVM to classify wood surface defects, Hu et al. proposed an algorithm based on ellipse fitting and distance threshold to detect steel shell surface pit defects, Chen et al. used smoothing filtering to detect steel plate surface defects, and Wang et al. proposed an aluminum foil defect detection algorithm based on the SUSAN operator. Although the above work has achieved good results in surface defect detection, there are still some problems, such as poor robustness, great limitations, low real-time performance, and the need to collect and construct a data set for aluminum surface defects, which is a large amount of work. Insufficient data leads to overfitting, and less feature information affects the training effect, which will all affect the final detection accuracy. SUMMARY

[0003] (I) Technical problems to be solved

[0004] Based on the above problems, the present application provides an aluminum surface real-time defect detection method and system based on improved YOLOv5, which solves the problems of low real-time performance, low detection accuracy and low training efficiency in aluminum surface defect detection.

[0005] (II) Technical solutions

[0006] Based on the above technical problems, the present application provides an aluminum surface real-time defect detection method based on improved YOLOv5, which comprises the following steps:

[0007] S1, obtain various aluminum surface defect pictures, perform data enhancement picture preprocessing, and establish a data set;

[0008] S2, input the pretreated data set into the improved YOLOv5 network structure of the ghost network, the joint attention mechanism and the deep separable convolution, and perform reinforcement migration training to obtain an optimized model; the improved YOLOv5 network structure of the ghost network, the joint attention mechanism and the deep separable convolution comprises:

[0009] The input picture is input into the CBL, the first Ghost module, the first C3Ghost module, the second Ghost module, the second C3Ghost module, the third Ghost module, the third C3Ghost module, the fourth Ghost module, the fourth C3Ghost module, and the attention module is embedded in the four C3Ghost modules; the output of the second C3Ghost module is concatenated with the output sampled from the first Dw convolution module, and then outputted from the fifth C3Ghost module as a first scale feature map; the output of the third C3Ghost module is concatenated with the output sampled from the third Dw convolution module, and then outputted from the sixth C3Ghost module, the first Dw convolution module, and the fifth C3Ghost module after the second Dw convolution module, and then outputted from the seventh C3Ghost module as a second scale feature map; the output of the fourth C3Ghost module is concatenated with the output of the third Dw convolution module after the SPPF, and then outputted from the seventh C3Ghost module as a third scale feature map; the C3Ghost module is a C3 module with the Ghost added, and the Dw convolution module is a deep separable convolution module;

[0010] S3, deploy the optimized model to a hardware device to perform real-time detection of aluminum surface defects.

[0011] Further, the step S2 comprises:

[0012] S21, input the pretreated or further strengthened data set into the improved YOLOv5 network structure of the ghost network, the joint attention mechanism and the deep separable convolution, and obtain a pre-training model by using migration learning;

[0013] S22, determine whether the accuracy of various defects reaches a set threshold value, if not, go to step S23, and if yes, go to step S24;

[0014] S23, further strengthen the data set corresponding to the defect whose accuracy does not reach the set threshold value, and return to step S21 for continuous training;

[0015] S24, obtain an optimized model by training.

[0016] Further, the step S23 further includes parameter fine-tuning.

[0017] Further, the step S22 sets the threshold value as 95%.

[0018] Further, the various defects include pinholes, dirt, and scratches.

[0019] Further, the attention module adopts a channel attention module CAM and a spatial attention module SAM connected in parallel, the height, width, and channel number of the input feature map F are H, W, and C respectively, in the CAM, the global spatial information of F is compressed by Max Pool and Avg Pool first to generate two feature maps S1 and S2 with a size of 1×1×C, the feature maps S1 and S2 pass through an MLP to obtain two one-dimensional feature maps, and the two one-dimensional feature maps are normalized to obtain a weight feature map MC; at the same time, in the SAM, a 1×1×1 convolution module is used to input the result into a Sigmoid function for activation to obtain a weight feature map MS; finally, the weight feature maps MC and MS are connected in parallel by element-wise addition, and after Sigmoid activation function, an output feature map F^ is obtained.

[0020] Further, the picture preprocessing in step S1 includes:

[0021] The aluminum surface defect pictures of different defect objects of different scales are pasted to new background pictures;

[0022] The aluminum surface defect pictures are adjusted by Gaussian blur;

[0023] Further, the step S23 further includes parameter fine-tuning.

[0024] The aluminum surface defect pictures are randomly selected four pictures to obtain new pictures by mosaic data enhancement splicing;

[0025] The aluminum surface defect pictures are adjusted by brightness;

[0026] The aluminum surface defect pictures are adjusted by rotation angle;

[0027] The aluminum surface defect pictures are adjusted by cropping;

[0028] The aluminum surface defect pictures are adjusted by translation;

[0029] The aluminum surface defect pictures are adjusted by mirroring.

[0030] Further, the input picture has been uniformly adjusted to have a height* width* channel number of 640*640*3.

[0031] Further, the high * width * channel number of the first scale feature map is 255*80*80, the high * width * channel number of the second scale feature map is 255*40*40, and the high * width * channel number of the third scale feature map is 255*20*20.

[0032] The application also discloses an aluminum surface real-time defect detection system based on an improved YOLOv5, comprising: at least one processor; and at least one memory in communication connection with the processor, wherein: the memory stores program instructions executable by the processor, and the processor calling the program instructions can execute the aluminum surface real-time defect detection method based on the improved YOLOv5.

[0033] (III) Beneficial effects

[0034] The above technical solution of the application has the following advantages:

[0035] (1) The improved YOLOv5 network structure is used in the application, the ghost network is introduced into the YOLOv5 network to reduce the model parameterization, the attention module of the joint attention mechanism is introduced to reduce the total parameter quantity of the model to simplify the model, the depth separable convolution is introduced to further reduce the model parameter quantity, so that the model is lightweight, the calculation amount is reduced, the model training speed is accelerated, the detection real-time performance is improved, and the data set is further strengthened through reinforcement migration learning during model training, so that the training results of various defects are satisfactory, the detection accuracy is further improved, the training efficiency is improved, and the detection real-time performance is improved.

[0036] (2) The application strengthens the feature information in the data set, especially the small target feature information such as pinhole defects, through pasting and Gaussian blur oversampling processing, overcomes the problem of less feature information and poor training effect, and further improves the detection precision.

[0037] (3) The application effectively expands the data set through Mosaic data enhancement and traditional data enhancement processing, solves the overfitting phenomenon caused by insufficient data set quantity, and further improves the detection precision. BRIEF DESCRIPTION OF DRAWINGS

[0038] The features and advantages of the application will be more clearly understood through reference to the accompanying drawings, which are schematic and should not be understood as limiting the application, in which:

[0039] Figure 1 It is a whole idea diagram of the aluminum surface real-time defect detection method based on the improved YOLOv5 of the embodiment of the application.

[0040] Figure 2 It is a picture preprocessing schematic diagram of the embodiment of the application through pasting and Gaussian blur.

[0041] Figure 3 A pre-processing schematic diagram of a sheared, occluded and noise-added picture of an embodiment of the present application;

[0042] Figure 4 A pre-processing schematic diagram of a picture of an embodiment of the present application that is randomly flipped and changed in brightness;

[0043] Figure 5 A structural network schematic diagram of an improved YOLOv5 of an embodiment of the present application;

[0044] Figure 6 A network schematic diagram of a Ghost module of an embodiment of the present application;

[0045] Figure 7 A network schematic diagram of an attention module of an embodiment of the present application;

[0046] Figure 8 A network schematic diagram of a depth separable convolution of an embodiment of the present application;

[0047] Figure 9 A column chart of average recognition accuracy of various defects of an embodiment of the present application;

[0048] Figure 10 A detection result schematic diagram of an embodiment of the present application. DETAILED DESCRIPTION

[0049] The specific embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. The following embodiments are used to illustrate the present application, but are not used to limit the scope of the present application.

[0050] An embodiment of the present application is an aluminum surface real-time defect detection method and system based on an improved YOLOv5, as shown in the following steps: Figure 1

[0051] S1, obtain various aluminum surface defect pictures, perform data enhanced picture preprocessing, and establish a data set; the data enhanced picture preprocessing includes:

[0052] paste the aluminum surface defect pictures of different defect objects of different scales to a new background picture;

[0053] adjust the aluminum surface defect pictures by Gaussian blur;

[0054] and includes at least one of the following processing methods:

[0055] randomly select four aluminum surface defect pictures to obtain a new picture through mosaic data enhancement splicing;

[0056] adjust the brightness of the aluminum surface defect pictures;​

[0057] The surface defect picture of the aluminum material is adjusted in rotation angle;

[0058] The surface defect picture of the aluminum material is adjusted in cutting;

[0059] The surface defect picture of the aluminum material is adjusted in translation;

[0060] The surface defect picture of the aluminum material is adjusted in mirror image.

[0061] In this embodiment, the aluminum sheet defect pictures of different objects of different scales are first pasted to a new background image; the pasting technique can quickly obtain rich and novel training data; then the pasted pictures are subjected to Gaussian blur processing, and Gaussian blur is an image blur filter which calculates the transformation of each pixel in the image using normal distribution; as shown in Figure 2 The pasting and Gaussian blur are used for oversampling processing to strengthen the feature information in the data set, especially to strengthen the small target feature information such as pinhole defects, expand the number of pinhole defect pictures, improve the proportion of pinhole defect pictures, and overcome the problems of less feature information and poor training effect.

[0062] Then four pictures are randomly selected through Mosaic data enhancement to obtain a new picture, each picture has its corresponding frame, and the new picture obtained by splicing also obtains the frame corresponding to the picture. Such a new picture is transmitted into a neural network to learn, which is equivalent to learning four pictures at a time; finally, traditional data enhancement means such as changing brightness, rotation angle, cutting, translation, mirror image, occlusion and adding noise are processed; as shown in Figure 3 and Figure 4 After these operations, the data set data is expanded by 10 times, the overfitting phenomenon caused by insufficient data set quantity is solved, and the data set is divided into a training set and a test set for subsequent training and learning.

[0063] In this embodiment, various defects include pinholes, dirt and scratches, etc., and other aluminum surface defect types can also be selected as needed.

[0064] S2, input the preprocessed data set into the improved YOLOv5 network structure of the ghost network, joint attention mechanism and depth separable convolution, and perform reinforcement migration training to obtain an optimized model; including the following steps:

[0065] S21, input the preprocessed or further enhanced data set into the improved YOLOv5 network structure of the ghost network, joint attention mechanism and depth separable convolution, and use migration learning to obtain a pre-trained model;

[0066] The migration learning here is a conventional migration learning, and the pre-training module is obtained through the conventional migration learning. Compared with the imitation learning and lifelong learning, the conventional migration learning method greatly improves the average accuracy and shortens the training time.

[0067] S22, judge whether the accuracy of various defects reaches the set threshold value, if not, go to step S23, if yes, go to step S24;

[0068] Whether the training result of various defects of the pre-training model is satisfied is judged through the test set. For the defects with unsatisfactory training result, go to step S23, further strengthen the data set of the defects, and return to step S21 for continuous training to obtain a new pre-training model, until the training result of various defects is satisfied. At this time, the pre-training model is the final optimization model.

[0069] S23, further strengthen the data set corresponding to the defects with accuracy not reaching the set threshold value, and return to step S21 for continuous training;

[0070] For the defects with unsatisfactory training result, such as the accuracy of the pictures of pinhole and dirt defects not reaching the set threshold value, i.e. 95%, the data set corresponding to the pinhole and dirt defects is further strengthened by the strengthening method in step S1, and after parameter fine-tuning, the training and subsequent training are continued by using the migration learning in step S21. The method of continuing the migration learning training by using the data set further strengthened according to the defects with unsatisfactory training result and the pre-training model at this time is the strengthened migration learning, so that the training result of various defects is satisfied, the average accuracy is further improved, and the training time is shortened.

[0071] S24, an optimization model is trained.

[0072] For the improved YOLOv5 network structure, a new detection algorithm based on the YOLOv5 algorithm is proposed. Based on the YOLOv5 algorithm, the Backbone layer is constructed based on the Ghost module, and the attention mechanism module is embedded in the Ghost module, realizing the compression of the Backbone backbone network and paying more attention to the channel and spatial information. Then, the deep separable convolution is used to compress the Neck network, so that the model volume is further reduced. As shown in the following Figure 5 , it includes:

[0073] The input picture is input into the CBL, the first Ghost module, the first C3Ghost module, the second Ghost module, the second C3Ghost module, the third Ghost module, the third C3Ghost module, the fourth Ghost module, the fourth C3Ghost module, and the attention module is embedded in the four C3Ghost modules; the output of the second C3Ghost module is concatenated with the output sampled from the first Dw convolution module, and then outputted as a first scale feature map through the fifth C3Ghost module; the output of the third C3Ghost module is concatenated with the output sampled from the third Dw convolution module, and then outputted as a second scale feature map through the sixth C3Ghost module, the first Dw convolution module, the fifth C3Ghost module, the second Dw convolution module, and the seventh C3Ghost module; the output of the fourth C3Ghost module is concatenated with the output of the third Dw convolution module and the output of the seventh C3Ghost module after the fourth Dw convolution module, and then outputted as a third scale feature map through the eighth C3Ghost module; wherein the C3Ghost module is a C3 module with a Ghost, the Dw convolution module is a depth separable convolution module, Concat represents the addition of the dimensions of two images, CBL is a basic structure composed of Conv, Bn and Leaky_relu activation function, and SPPF is Spatial Pyramid Pooling-Fast spatial pyramid pooling-Fast.

[0074] According to the above network model, the input picture is uniformly adjusted to have a height* width* channel number of 640*640*3, and three scale feature maps are extracted at different levels by the backbone network; the output of the second C3Ghost module is an image of 128*80*80, and a first scale feature map of 255*80*80 is outputted after processing, the output of the third C3Ghost module is an image of 256*40*40, and a second scale feature map of 255*40*40 is outputted after processing, and the output of the fourth C3Ghost module is an image of 512*20*20, and a third scale feature map of 255*20*20 is outputted after processing.

[0075] The Ghost network is introduced in the YOLOv5 algorithm to reduce the model parameter amount. The Ghost network is a network structure based on the Ghost convolution module. The traditional CNN structure usually achieves ideal precision through a large amount of floating point operation, and although the light weight models such as MobileNet and ShuffleNet reduce the floating point calculation amount, the redundant feature maps generated by convolution are not effectively processed. Figure 6As shown, the Ghost convolution module first generates some basic original feature maps through 1x1 normal convolution operation, and then processes these feature maps one by one through Φ1, Φ2, …, Φ k Linear transformation, get another part of redundant feature map after this part of feature map and the original feature map fusion, increase the number of channels. This way of getting redundant feature maps through linear operation can generate those redundant feature maps with less cost compared to normal convolution. Reduce the total parameter amount of the model in this way to simplify the model.

[0076] Embedding joint attention mechanism UAM, namely attention module, in the model structure can reduce the loss of model accuracy in the model compression process. The joint attention mechanism UAM is composed of channel attention module CAM and spatial attention module SAM connected in parallel. The parallel structure encodes the feature map information in spatial and channel dimensions at the same time, which can better utilize the information between the two layers of feature map channels and space. The detailed structure diagram of UAM is as shown in Figure 7 , wherein F is the input feature map, H, W, and C are the height, width, and channel number of the input feature map, respectively. In CAM, first, the global spatial information of F is compressed through Max Pool and Avg Pool to generate two feature maps S1 and S2 with the size of 1x1xC; then two one-dimensional feature maps are obtained through Multi Layer Perception (MLP); the two one-dimensional feature maps are normalized to obtain the weight feature map MC. At the same time, in SAM, first, a 1x1x1 convolution module is used, and then the result is input into the Sigmoid function for activation to obtain the weight feature map MS. Finally, MC and MS are connected in parallel by element-wise addition, and the output feature map F^ is obtained after Sigmoid activation function.

[0077] Depthwise separable convolution (DwConv) is used in the NECK network of YOLOv5 to further reduce the model parameter amount. As shown in Figure 8As shown, the depth separable convolution is composed of two parts of depthwise convolution (DWConv) and pointwise convolution (PWConv). Assuming that the input data high*wide is 7*1*3, first, the depthwise convolution is performed, and because the input channel number is 3, 3 3*1*1 convolution kernels are used for convolution operation, the feature map output is 5*1*3, the calculation amount of the depthwise convolution process is 1*3*3*5=45, and the parameter training number is 1*3*3=9; then, the pointwise convolution is performed, if 16 feature values are to be obtained, 16 1*1*3 convolution kernels are required for convolution operation, finally, the feature map output is 5*1*16, the calculation amount of the pointwise convolution process is 1*3*5*16=240, and the parameter training number is 3*16=48. From the above calculation, it can be known that the total calculation amount of the depth separable convolution neural network training process is 285, and the total parameter number is 57. If the traditional convolution is performed, the total calculation amount is 1*3*3*5*16=720, and the total parameter number is 1*3*3*16=144, which is much higher than the calculation amount and the parameter training number of the depth separable convolution. Therefore, compared with the traditional convolution, the depth separable convolution can effectively reduce the calculation amount, reduce the parameter training number, and accelerate the model training speed.

[0078] S3, deploying the optimization model to a hardware device for real-time detection of surface defects of aluminum materials.

[0079] The optimized model is deployed on a hardware device. The hardware device includes an LED light source, a CCD image sensor, a 7-inch touch screen, a host computer NVIDIA Jetson Nano, an encoder, a conveyor belt and two power supplies, the host computer is connected with the light source, image sensor, touch screen and encoder respectively, the conveyor belt is used for conveying aluminum materials to be detected, the light source is located at one side of the conveyor belt and shoots at the aluminum materials to be detected passing on the conveyor belt, and the imaging element includes an imaging lens and an image sensor, wherein the image sensor is used for scanning the imaging image of the imaging lens and sending the imaging image to the host computer for processing. The host computer NVIDIA Jetson Nano, by comparing the performance parameters of Nano and TX2, it is found that the running power of Nano is as low as 10W, and the performance of up to 32TOPS is 20 times that of TX2. The 8-core ARM v8.2 64-bit CPU, 512-core Volta GPU and 7-channel VLIW vision processor owned by Nano ensure the powerful computing capability of Nano, and the high computing performance feature of Nano is also suitable for a large amount of image processing and training and running of deep learning model. Because of its low power consumption, it can ensure the long-time and effective performance of the experiment under outdoor test conditions. As a new generation of autonomous machine embedded system, the performance provided by the NVIDIA Jetson Nano can improve the running speed of the autonomous machine software and reduce the power consumption. Each system is a complete modular system (SOM) with CPU, GPU, PMIC, DRAM and memory, which can save development time and cost and has scalability, and the SOM suitable for the application occasion can be selected to build a customized system. The role of Nano in the real-time defect detection system of aluminum material surface mainly includes the following three aspects: (1) carrying and running the main program; (2) used as a central control device, connected with the display screen and camera through the USB expansion port and various interfaces provided by the development kit carrier board; (3) image processing and analysis, deep learning model training and running.

[0080] The original data set of 100 pictures is used as a test set for detection, and all experiments are performed on a Windows 11 operating system equipped with an Intel i7-12700 CPU and a NVIDIA GeForce RTX 3090 24GB GPU. These methods are implemented in Python 3.8 and use Pytorch 1.11 as a neural network framework. To ensure the accuracy of the training results, the algorithms involved in the comparison are tested under the same training parameters. The model training parameters are set as follows: the batch size is 32, the learning rate is 0.0025, the momentum is 0.937, and the weight decay is 0.0005. The map(0.5, 11point) is used as the detection index, and the average recognition accuracy of each type of defect is as shown in Figure 9 The pinhole recognition accuracy is 94.4%, the scratch is 98.3%, the dirt is 99.5%, and the overall average accuracy is 97.4%. Compared with the YOLOv5s model, the convolution model size of the embodiment is reduced by 74.3%, only 3.7MB, and the overall average accuracy of the map is 97.4%. An automatic detection aluminum surface defect detection equipment is manufactured, which can detect the aluminum surface defects in real time, the detection frame rate is 24.5fps, and the equipment weight is only 0.85kg, which is convenient to carry. The visual detection result is as shown in Figure 10 .

[0081] Finally, it should be noted that the above detection method can be converted into software program instructions, which can be implemented by a detection system including a processor and a memory, or by computer instructions stored in a non-transitory computer readable storage medium. The integrated unit implemented in the form of software function unit described above can be stored in a computer readable storage medium. The software function unit described above is stored in a storage medium, including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute part of the steps of the method described in each embodiment of the application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0082] In summary, the aluminum surface real-time defect detection method and system based on the improved YOLOv5 has the following beneficial effects:

[0083] (1) The improved YOLOv5 network structure is introduced into the ghost network to reduce the model parameterization, the attention module of the joint attention mechanism is introduced to reduce the total parameter quantity of the model to simplify the model, the depth separable convolution is introduced to further reduce the model parameter quantity, so that the model is lightened, the calculation amount is reduced, the model training speed is accelerated, the detection real-time performance is improved, and the data set is further strengthened through reinforcement migration learning during model training, so that the training results of various defects are satisfactory, the detection accuracy is further improved, the training efficiency is improved, and the detection real-time performance is improved;

[0084] (2) The present application strengthens the feature information in the data set, especially the small target feature information such as pinhole defects, through pasting and Gaussian blur oversampling processing, overcomes the problem of less feature information and poor training effect, and further improves the detection accuracy;

[0085] (3) The present application effectively expands the data set through Mosaic data enhancement and traditional data enhancement processing, solves the overfitting phenomenon caused by insufficient data set quantity, and further improves the detection accuracy.

[0086] Finally, it should be noted that: the above examples are only used to illustrate the technical solutions of the present application, and not to limit them; although the embodiments of the present application are described in conjunction with the drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present application, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A real-time defect detection method for aluminum surfaces based on an improved YOLOv5, characterized in that, Includes the following steps: S1. Obtain images of various aluminum surface defects, perform image preprocessing for data augmentation, and establish a dataset; S2. Input the preprocessed dataset into the improved YOLOv5 network structure with Ghost network, joint attention mechanism and depthwise separable convolution, and perform reinforcement transfer training to obtain the optimized model; The improved YOLOv5 network architecture, which incorporates a ghost network, a joint attention mechanism, and depthwise separable convolutions, includes: The input image is processed through CBL, a first Ghost module, a first C3Ghost module, a second Ghost module, a second C3Ghost module, a third Ghost module, a third C3Ghost module, a fourth Ghost module, and a fourth C3Ghost module, with an attention module embedded in each of the four C3Ghost modules. The output of the second C3Ghost module is concatenated with the output upsampled from the first Dw convolutional module and then processed by a fifth C3Ghost module to output a first-scale feature map. The output of the third C3Ghost module is concatenated with the output upsampled from the third Dw convolutional module. Then, the output of the sixth C3Ghost module and the first Dw convolutional module is concatenated with the output of the fifth C3Ghost module after passing through the second Dw convolutional module, and then output as a second-scale feature map by the seventh C3Ghost module; the output of the fourth C3Ghost module is concatenated with the output of the third Dw convolutional module after passing through the SPPF module and the seventh C3Ghost module after passing through the fourth Dw convolutional module, and then output as a third-scale feature map by the eighth C3Ghost module; the C3Ghost module is a C3 module with Ghost added, and the Dw convolutional module is a depthwise separable convolutional module; S3. Deploy the optimized model onto hardware devices for real-time detection of surface defects in aluminum materials.

2. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 1, characterized in that, Step S2 includes: S21. Input the preprocessed or further enhanced dataset into the improved YOLOv5 network structure of Ghost Network, Joint Attention Mechanism and Deeply Separable Convolution, and use transfer learning to obtain the pre-trained model. S22. Determine whether the accuracy of various defects has reached the set threshold. If not, proceed to step S23; if yes, proceed to step S24. S23. Further enhance the dataset corresponding to the defects whose accuracy has not reached the set threshold, and return to step S21 to continue training. S24. The optimized model is obtained through training.

3. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 2, characterized in that, Step S23 also includes parameter fine-tuning.

4. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 2, characterized in that, In step S22, the set threshold is 95%.

5. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 2, characterized in that, The various defects include pinholes, dirt, and scratches.

6. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 1, characterized in that, The attention module employs a channel attention module (CAM) and a spatial attention module (SAM) connected in parallel. The height, width, and number of channels of the input feature map F are H, W, and C, respectively. In the CAM, the global spatial information of F is first compressed using Max Pooling and Avg Pooling to generate two feature maps S1 and S2 with a size of 1×1×C. The feature maps S1 and S2 are processed by MLP to obtain two one-dimensional feature maps. The two one-dimensional feature maps are then normalized to obtain a weight feature map MC. Simultaneously, in the SAM, a 1×1×1 convolution module is first used to input the result into a Sigmoid function for activation to obtain a weight feature map MS. Finally, the weight feature maps MC and MS are connected in parallel using element-wise addition and activated by the Sigmoid function to obtain the output feature map F^.

7. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 1, characterized in that, The image preprocessing in step S1 includes: Paste images of aluminum surface defects of different sizes and defects onto a new background image; The image of the surface defects of the aluminum material is adjusted using Gaussian blur; And includes at least one of the following processing methods: Four images of surface defects on the aluminum material are randomly selected and stitched together using mosaic data enhancement to obtain a new image. The brightness of the image showing surface defects in the aluminum material is adjusted. The image of the surface defects of the aluminum material is rotated and the angle is adjusted. The image of the surface defects of the aluminum material is cropped and adjusted; The image of the surface defects of the aluminum material is shifted and adjusted. The image of the surface defects of the aluminum material is mirrored.

8. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 1, characterized in that, The input images have been uniformly adjusted to a height*width*channel number of 640*640*3.

9. The method for real-time defect detection of aluminum surfaces based on improved YOLOv5 according to claim 8, characterized in that, The height * width * number of channels of the first scale feature map is 255 * 80 * 80, the height * width * number of channels of the second scale feature map is 255 * 40 * 40, and the height * width * number of channels of the third scale feature map is 255 * 20 * 20.

10. A real-time defect detection system for aluminum surfaces based on an improved YOLOv5, characterized in that, include: At least one processor; and at least one memory communicatively connected to the processor, wherein: The memory stores program instructions that can be executed by the processor, and the processor can execute the real-time aluminum surface defect detection method based on the improved YOLOv5 as described in any one of claims 1 to 9 by calling the program instructions.