Aluminum profile surface defect detection method and storage medium
By optimizing image quality through wavelet transform and data enhancement techniques and improving the YOLOv8 network structure, the problems of accuracy and real-time performance in detecting minute defects on aluminum profile surfaces were solved, achieving high-precision and high-efficiency detection results.
Patent Information
- Application Number
- CN202511809315.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-03
- Publication Date
- 2026-02-27
AI Technical Summary
Existing methods for detecting surface defects in aluminum profiles are insufficient in terms of improving the accuracy of detecting minute defects, adapting to sample imbalance, and improving detection efficiency, making it difficult to meet the high precision and real-time requirements of industrial scenarios.
Wavelet transform filtering algorithm is used for image preprocessing. CutMix and Mosaic data augmentation techniques are combined to construct a balanced dataset. The YOLOv8 network structure is improved, including the C2f_Faster_DCNv3 module, ADFR module and Focaler-IoU loss function. The model training and deployment on the TensorRT platform are optimized to improve detection accuracy and speed.
It significantly improves the accuracy of detecting minute defects, enhances the model's sample adaptability and generalization ability, meets the real-time detection needs of industrial sites, and reduces the cost of manual inspection.
Smart Images

Figure CN121582231A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of aluminum profile quality detection, and specifically relates to an aluminum profile surface defect detection method and a storage medium. BACKGROUND
[0002] As a key structural material with aluminum alloy as the core material, aluminum profiles have been widely used in modern industrial manufacturing and construction engineering due to their excellent characteristics such as light weight, high strength, corrosion resistance and easy processing. However, during the production of aluminum profiles, various defects may occur on the surface due to multiple factors such as processing process stability, production equipment state and on-site environmental conditions, including non-conductive, orange peel, bottom leakage, paint bubble, jet flow, scratch, pit, color spot and dirty spot. These surface defects not only seriously affect the appearance quality of aluminum profiles, but also may weaken their structural strength and safety, so efficient and accurate defect detection of the surface of aluminum profiles is a key link to ensure product quality.
[0003] In the current aluminum profile surface defect detection task, there are many challenges in improving the detection accuracy of small defects such as dirty spots, scratches and paint bubbles: Firstly, the problem of sample imbalance and small target is prominent. In the training samples collected in the industrial field, the number of small target defect samples such as fine dirty spots is much smaller than that of normal samples or large size defect samples, which makes it difficult for the detection model to fully learn the characteristics of small defects and prone to missed detection and false detection. Secondly, the small defects have small proportion in the image, high similarity with the background features and large scale difference, which requires the detection model to have strong multi-scale feature extraction capability. Thirdly, low-quality image samples produced under different production batches and different imaging conditions will reduce the generalization performance of the model and affect the detection stability.
[0004] The existing detection methods have obvious shortcomings in dealing with the above problems. Traditional machine vision detection methods are difficult to adapt to complex defect features and multi-scale detection requirements, and conventional deep learning models perform poorly in small defect feature extraction, sample imbalance adaptation and inference speed balancing, which cannot meet the dual requirements of detection accuracy and real-time performance in industrial scenarios. Therefore, there is an urgent need for an aluminum profile surface defect detection scheme that can accurately capture small defect features, balance sample differences and consider detection efficiency. SUMMARY
[0005] In view of the above situation, in order to overcome the defects of the prior art, the application provides an aluminum profile surface defect detection method and a storage medium, which effectively solves the problems proposed in the background art.
[0006] To achieve the above purpose, the application provides the following technical scheme: an aluminum profile surface defect detection method, comprising the following steps: Step S1: Image preprocessing and dataset construction S1.1, Image denoising processing: the original aluminum profile image is preprocessed using wavelet transform filtering algorithm, bior4.4 wavelet basis function is selected to decompose the image containing noise, and the low-frequency component and high-frequency component of the image are obtained; the high-frequency component is denoised by threshold method to remove noise interference; finally, the denoised image with improved clarity and contrast is output through wavelet reconstruction and histogram equalization processing, enhancing the discrimination of micro defects and background; S1.2, Dataset expansion and balance: for the problem of unbalanced defect samples in industrial scene, random rotation, scaling, brightness adjustment and other data enhancement operations are performed on the rare defect samples; at the same time, CutMix and Mosaic data enhancement techniques are applied to expand the number of defect samples; the processed images are labeled as txt files in YOLO format using LabelImg tool, and an aluminum profile surface defect dataset containing multiple defect types and balanced sample distribution is constructed; Step S2: Improved YOLOv8 network structure design S2.1, Improvement of backbone network: replace the C2f module in the original YOLOv8 with the hierarchical fusion C2f_Faster_DCNv3 module; the module contains two branches: one is the DCNv3 branch, whose convolution kernel sampling point can be adaptively adjusted according to the defect shape to enhance the feature extraction ability of irregular shape defects such as scratches and paint bubbles; the other is the FasterBlock branch, which replaces ordinary convolution operation with partial convolution to reduce computational complexity and memory access cost; adopt adaptive proportional adjustment strategy of weighted average, shallow features are preferentially processed by FasterBlock to reduce computational complexity, and deep features are processed by DCNv3 to improve complex feature extraction accuracy, achieving a balance between detection accuracy and speed; S2.2, Improvement of neck network: based on the CAFR idea, an aluminum profile defect special feature reorganization module ADFR is constructed, which integrates channel attention mechanism and spatial attention mechanism; the channel attention mechanism calculates the importance weight of each feature channel to strengthen the expression of defect-related feature channels; the spatial attention mechanism focuses on the image area where the defect may appear, highlighting the spatial position information of the micro defect; through adaptive weighting, multi-scale feature fusion is realized to enhance the feature expression ability of micro defects; S2.3, Improvement of detection head: based on the original Anchor-Free decoupling head of YOLOv8, an additional detection head is added at the P2 layer of the feature pyramid to capture pixel-level micro defects and make up for the problem of insufficient response of traditional detection head to small-scale defects; S2.4, loss function optimization: replace the original loss function with the Focaler-IoU loss function, give the micro defect a higher loss weight through the weighting strategy, improve the model's attention to difficult samples, reduce the dominant role of easy-to-detect samples in loss calculation, and further improve the micro defect detection accuracy; Step S3: model training and deployment S3.1, training environment building: under the Windows operating system, build a deep learning training and inference environment based on python3.8, CUDA11.8, cuDNN8.6, PyTorch2.4.1, and TensorRT8.2.5.1; S3.2, two-stage training strategy: the first stage imports the weights pre-trained on a large-scale general dataset to provide the model with initial feature extraction capability; the second stage is trained and fine-tuned on the aluminum profile defect dataset, and the training parameters are set as follows: the random gradient descent optimizer is used, the momentum is 0.923, the confidence threshold is 0.35, the IoU threshold is 0.35, the training period is 300 rounds, the input image size is 640*640, the batch size is 16, the initial learning rate is 0.01, and Mosaic data enhancement is used in the training process to ensure that the model fully learns the aluminum profile defect features; S3.3, inference acceleration deployment: convert the trained model weight into ONNX format, and further deploy it to the TensorRT platform to generate an inference engine, which improves the model inference speed through the model optimization and acceleration capabilities of TensorRT, and meets the real-time detection requirements of industrial sites.
[0007] Preferably, the threshold value calculation formula of the threshold value method in step S1.1 is λ=σ√(2lnN), wherein σ is the noise standard deviation, and N is the total number of image pixels.
[0008] Preferably, the convolution kernel sampling point offset range of the DCNv3 branch in step S2.1 is [-3, 3].
[0009] The storage medium is a computer readable storage medium, and the computer readable storage medium stores a computer program of an aluminum profile surface defect detection method.
[0010] Compared with the prior art, the beneficial effects of the present application are: 1. Significant improvement in micro-defect detection accuracy: Wavelet denoising and histogram equalization are used to optimize image quality and enhance the recognition of micro-defect features. C2f_Faster_DCNv3 module and ADFR module are used to strengthen multi-scale feature extraction and fusion capability. P2 layer detection head is added to adapt to micro-defects. Focaler-IoU loss function is weighted to improve the attention of difficult samples, effectively solving the problems of micro-defect missed detection and false detection. 2. Strong sample adaptability and generalization ability: CutMix, Mosaic and other data enhancement techniques are used to balance sample distribution and reduce the impact of sample imbalance on model training. The improved network structure has stronger adaptability to low-quality images under different production batches and imaging conditions, improving the generalization performance of the model in actual industrial scenarios. 3. Detection speed and accuracy: FasterBlock branch reduces computational complexity, and TensorRT inference accelerates deployment efficiency. Under the premise of ensuring detection accuracy, it meets the real-time detection needs of industrial production, achieving the dual goals of "high precision + high speed". 4. Wide application value and promotion prospects: This method is designed for common defects on the surface of aluminum profiles, and the detection process is consistent with the actual industrial production. It is easy to deploy and can be directly applied to online detection of aluminum profile production lines, helping to improve product quality control and reduce labor costs, with significant practical value and promotion potential. BRIEF DESCRIPTION OF DRAWINGS
[0011] The accompanying drawings are used to provide a further understanding of the present application, and form a part of the specification, together with the embodiments of the present application, to explain the present application, and do not constitute a limitation of the present application.
[0012] In the drawings: Fig. 1 The overall flowchart of the aluminum profile surface defect detection method of the present application; Fig. 2 The specific flowchart of wavelet denoising processing of the present application; Fig. 3 The overall structure diagram of the improved YOLOv8 network of the present application; DETAILED DESCRIPTION The technical solutions in the embodiments of the present application will be described in detail below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0013] By Figs. 1-3The present application relates to a method for detecting surface defects of aluminum profiles, comprising the following steps: Step S1: image preprocessing and dataset construction S1.1, image denoising processing: the original aluminum profile image is preprocessed by using a wavelet transform filtering algorithm, a bior4.4 wavelet basis function is selected to decompose the image containing noise, and the low-frequency component (retaining the main features of the image) and the high-frequency component (containing noise information) of the image are obtained; the high-frequency component is denoised by threshold method to remove noise interference; finally, the denoised image with improved clarity and contrast is output through wavelet reconstruction and histogram equalization processing, enhancing the discrimination of micro defects and background; S1.2, dataset expansion and balance: in view of the defect sample imbalance problem in industrial scene, random rotation, scaling, brightness adjustment and other data enhancement operations are performed on the rare defect samples; at the same time, CutMix and Mosaic data enhancement techniques are applied to expand the number of defect samples; the processed images are labeled as txt files in YOLO format using LabelImg tool, and an aluminum profile surface defect dataset containing multiple defect types and balanced sample distribution is constructed; Step S2: improved YOLOv8 network structure design S2.1, improvement of backbone network: replace the C2f module in the original YOLOv8 with the hierarchical fusion C2f_Faster_DCNv3 module; the module contains two branches: one is the DCNv3 branch, whose convolution kernel sampling point can be adjusted adaptively according to the defect shape to enhance the feature extraction ability of irregular shape defects such as scratches and paint bubbles; the other is the FasterBlock branch, which replaces ordinary convolution operation with partial convolution to reduce computational complexity and memory access cost; an adaptive proportion adjustment strategy based on weighted average is adopted, shallow features are preferentially processed by FasterBlock to reduce computational complexity, and deep features are processed by DCNv3 to improve complex feature extraction accuracy, achieving a balance between detection accuracy and speed; S2.2, improvement of neck network: based on the CAFR idea, an aluminum profile defect special feature reorganization module ADFR is constructed, which integrates channel attention mechanism and spatial attention mechanism; the channel attention mechanism calculates the importance weight of each feature channel to strengthen the expression of defect-related feature channels; the spatial attention mechanism focuses on the image region where the defect may appear, highlighting the spatial position information of the micro defect; multi-scale feature fusion is realized through adaptive weighting to enhance the feature expression ability of micro defects; S2.3, improvement of detection head: based on the original Anchor-Free decoupling head of YOLOv8, an additional detection head is added at the P2 layer (1 / 4 downsampling rate) of the feature pyramid, which is specially used to capture pixel-level micro defects and make up for the problem of insufficient response of traditional detection head to small-scale defects; S2.4, loss function optimization: replace the original loss function with the Focaler-IoU loss function, give a higher loss weight to the micro defect through the weighting strategy, improve the model's attention to difficult samples (micro defects, low contrast defects), reduce the dominant role of easy-to-detect samples in loss calculation, and further improve the detection accuracy of micro defects; Step S3: model training and deployment S3.1, training environment building: under the Windows operating system, build a deep learning training and inference environment based on python3.8, CUDA11.8, cuDNN8.6, PyTorch2.4.1, and TensorRT8.2.5.1; S3.2, two-stage training strategy: the first stage imports the weights pre-trained on a large-scale general dataset to provide the model with initial feature extraction capability; the second stage is trained and fine-tuned on the aluminum profile defect dataset, and the training parameters are set as follows: the stochastic gradient descent (SGD) optimizer is used, the momentum Momentum=0.923, the confidence threshold=0.35, the IoU threshold=0.35, the training period (epochs)=300 rounds, the input image size=640x640, the batch size (BatchSize)=16, the initial learning rate=0.01, and the Mosaic data enhancement is used in the training process to ensure that the model fully learns the aluminum profile defect features; S3.3, inference acceleration deployment: convert the trained model weights into ONNX format, and further deploy them to the TensorRT platform to generate an inference engine, which improves the model inference speed through the model optimization and acceleration capabilities of TensorRT, and meets the real-time detection requirements of industrial sites.
[0014] The threshold calculation formula of the threshold method in step S1.1 of the embodiment is λ=σ√(2lnN), where σ is the noise standard deviation, and N is the total number of image pixels.
[0015] The convolution kernel sampling point offset range of the DCNv3 branch in step S2.1 of the embodiment is [-3, 3].
[0016] The storage medium is a computer-readable storage medium, and the computer program of the aluminum profile surface defect detection method is stored in the computer-readable storage medium. When the computer program is executed by the processor, the steps of the above aluminum profile surface defect detection method are realized.
[0017] Specifically as follows: (I) Image preprocessing implementation steps A set of original images of aluminum profile surface defects is collected, covering common defect types such as non-conductive, orange peel, bottom leakage, paint bubbles, spray flow, scratches, pits, color spots, and dirty spots. The image resolution is uniformly adjusted to 640x640; Wavelet denoising processing is performed on the original image: the bior4.4 wavelet basis function is selected to perform 3-level decomposition on the image using the Python wavelet analysis library, obtaining cA3 (low-frequency component), cH3, cV3, and cD3 (high-frequency component). The adaptive threshold method is used to denoise the high-frequency components cH3, cV3, and cD3, with the threshold calculation formula being λ=σ√(2lnN), where σ is the noise standard deviation and N is the total number of image pixels. Wavelet reconstruction is performed on the denoised high-frequency components and low-frequency components to obtain a preliminary denoised image. The image gray scale distribution is adjusted through histogram equalization to improve the contrast, and the final denoised image is output. Dataset construction: Random rotation (angle range -15°-15°), scaling (scale range 0.8-1.2), and brightness adjustment (brightness coefficient 0.7-1.3) are performed on the sparse defect samples. The CutMix technique is applied to splice two defect images after cutting them at a random ratio, and the Mosaic technique is applied to splice four defect images in a grid arrangement. The LabelImg tool is used to manually label the defect positions and categories, generating a YOLO format txt annotation file. The training set, validation set, and test set are divided in a ratio of 8:1:1, and the aluminum profile surface defect dataset is constructed. (II) Improved YOLOv8 network building and training Network building: The improved YOLOv8 network is built based on the PyTorch2.4.1 framework, with the backbone network replaced by the C2f_Faster_DCNv3 module. The FasterBlock reduces the computational load through partial convolution (convolution kernel size 3x3, step 1, padding=1), and the DCNv3 module sets the offset range to [-3, 3]. The ADFR module is inserted into the neck network, with channel attention using the SE module structure and spatial attention using the CBAM module structure. The detection head is added to the feature pyramid P2 layer (output feature map size 160x160), including convolution layers (3x3), activation layers (SiLU), and output layers (predicted categories and coordinates). The loss function is set to Focaler-IoU, and the small defect loss weight coefficient is set to 2.0. Model training: import COCO dataset pre-training weight, initialize network parameters; set training parameters: SGD optimizer, momentum 0.923, weight decay 0.0005, initial learning rate 0.01, use cosine annealing learning rate scheduling strategy, train for 300 rounds, the first 5 rounds are warm-up training, and the learning rate is linearly increased to 0.01; batch size 16, real-time monitoring of the mAP (average precision mean) and loss value of the validation set during training, when the validation set mAP has no improvement for 10 consecutive rounds, stop training and save the optimal model weight; (Three) model deployment and detection implementation Model format conversion: use the official tool of PyTorch to convert the.pth format model weight saved by training into ONNX format, and specify the input image size as 640x640 and the output as defect class probability and bounding box coordinates during conversion; TensorRT inference deployment: in the TensorRT8.2.5.1 environment, load the ONNX format model, perform model quantization (INT8 quantization) and optimization, and generate a TensorRT inference engine; after the image to be detected is processed according to the pretreatment process (denoising, size adjustment), it is input into the inference engine, and the defect detection result (category, position, confidence) is output; Detection result judgment: set the confidence threshold to 0.35 and the IoU threshold to 0.35, perform non-maximum suppression (NMS) processing on the detection result, and eliminate duplicate detection boxes; output the final detection result, including defect type, position coordinates and confidence, when the confidence is greater than or equal to 0.35, it is judged as an effective defect, otherwise it is judged as no defect.
[0018] (Four) storage medium implementation The computer program code of the above-mentioned aluminum profile surface defect detection method is stored in a computer readable storage medium, which includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a hard disk, an optical disk, etc. When the computer program is called and executed by the processor, the whole process steps of image preprocessing, model training, and inference detection can be realized, which is convenient for method transplantation and popularization and application.
[0019] It should be noted that in this paper, relationship terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or equipment.
[0020] While embodiments of the present application have been shown and described, it is to be understood that various modifications, substitutions, replacements and variations can be made to these embodiments without departing from the principles and spirit of the present application, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for detecting surface defects in aluminum profiles, comprising the following steps: Step S1: Image Preprocessing and Dataset Construction S1.1 Image Denoising Processing: The original aluminum profile image is preprocessed using a wavelet transform filtering algorithm. The Bior 4.4 wavelet basis function is selected to decompose the noisy image to obtain the low-frequency and high-frequency components of the image. The high-frequency components are denoised using a thresholding method to remove noise interference. Finally, wavelet reconstruction and histogram equalization are used to output a denoised image with improved clarity and contrast, enhancing the distinction between minor defects and the background. S1.2 Dataset Expansion and Balancing: To address the imbalance of defect samples in industrial scenarios, data augmentation operations such as random rotation, scaling, and brightness adjustment are performed on sparse defect samples; at the same time, CutMix and Mosaic data augmentation techniques are applied to expand the number of defect samples; the LabelImg tool is used to annotate the processed images in YOLO format as txt files to construct a surface defect dataset for aluminum profiles containing multiple defect types and with a balanced sample distribution. Step S2: Improve the YOLOv8 network architecture design S2.1 Backbone Network Improvement: The original C2f module in YOLOv8 is replaced with a layered fusion C2f_Faster_DCNv3 module. This module contains two branches: one is the DCNv3 branch, whose convolution kernel sampling points can adaptively adjust their positions according to the defect shape, enhancing the feature extraction capability for irregularly shaped defects such as scratches and paint bubbles; the other is the FasterBlock branch, which replaces ordinary convolution operations with partial convolutions, reducing computational cost and memory access cost. An adaptive scaling strategy with weighted averages is adopted, where shallow features are processed first through FasterBlock to reduce computational cost, and deep features are processed through DCNv3 to improve the accuracy of complex feature extraction, achieving a balance between detection accuracy and speed. S2.2 Neck Network Improvement: Based on the CAFR concept, construct the ADFR (Advanced Feature Reconstruction Module) for aluminum profile defects, integrating channel attention mechanism and spatial attention mechanism; The channel attention mechanism calculates the importance weight of each feature channel, enhancing the expression of defect-related feature channels; Spatial attention mechanisms focus on image regions where defects may occur, highlighting the spatial location information of minute defects. Multi-scale feature fusion is achieved through adaptive weighting, enhancing the feature representation capability of minute defects; S2.3, Detection Head Improvement: While retaining the original Anchor-Free decoupling head of YOLOv8, an additional detection head is added to the P2 layer of the feature pyramid, which is specifically used to capture pixel-level micro-defects and make up for the problem of insufficient response of traditional detection heads to small-scale defects. S2.4 Loss Function Optimization: The original loss function is replaced with the Focaler-IoU loss function. By using a weighting strategy, small defects are given higher loss weights, which increases the model's focus on fitting difficult samples and reduces the dominant role of easily detectable samples in loss calculation, thereby further improving the detection accuracy of small defects. Step S3: Model Training and Deployment S3.1 Training Environment Setup: On the Windows operating system, set up a deep learning training and inference environment based on Python 3.8, CUDA 11.8, cuDNN 8.6, PyTorch 2.4.1, and TensorRT 8.2.5.1; S3.2 Two-stage training strategy: The first stage imports weights pre-trained on a large-scale general dataset to provide the model with initial feature extraction capabilities; The second stage involves training and fine-tuning on the constructed aluminum profile defect dataset. The training parameters are set as follows: stochastic gradient descent optimizer, momentum = 0.923, confidence threshold = 0.35, IoU threshold = 0.35, training cycle = 300 rounds, input image size = 640×640, batch size = 16, initial learning rate = 0.
01. Mosaic data augmentation is used during training to ensure that the model fully learns the features of aluminum profile defects. S3.3, Accelerated Inference Deployment: The trained model weights are converted to ONNX format and then deployed to the TensorRT platform to generate an inference engine. Through TensorRT's model optimization and acceleration capabilities, the model inference speed is improved to meet the real-time detection needs of industrial sites.
2. The method for detecting surface defects in aluminum profiles according to claim 1, characterized in that, The threshold calculation formula for the threshold method described in step S1.1 is λ=σ√(2lnN), where σ is the noise standard deviation and N is the total number of image pixels.
3. The method for detecting surface defects in aluminum profiles according to claim 1, characterized in that, The range of the convolution kernel sampling point offset for the DCNv3 branch in step S2.1 is [-3, 3].
4. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, which stores a computer program for the aluminum profile surface defect detection method as described in any one of claims 1-3. When the computer program is executed by a processor, it implements the steps of the aluminum profile surface defect detection method described above.
Citation Information
Cited By
Intelligent metal corrosion area calculation method based on YOLO segmentation model
CN122134788A