A lightweight multi-scale aluminum profile surface defect detection method
Patent Information
- Application Number
- CN202410242738.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-04
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2044-03-04
AI Technical Summary
[0004]目前,目标检测算法YOLOv7常常作为工业界使用的缺陷检测算法,由于铝型材表面缺陷种类多、长宽比例悬殊,且存在个别类别的缺陷尺寸很小,YOLOv7算法应用在铝型材表面缺陷检测领域的效果不尽如人意,存在漏检率高、检测精度低的问题
1)本发明了一种基于YOLOv7改进的多尺度缺陷检测的轻量化网络,在构建检测模型时,YOLOv7网络中存在大量的ELAN结构,使用深度可分离卷积DWConv来替换ELAN结构中的3x3普通卷积,可以减小模型计算量,除去冗余信息;在主干网络引入Selective KernelNetworks注意力机制,自适应地调整感受野尺寸,减小不重要信息的权重;采用BiFPN 双向特征金字塔网络结构作为网络的Neck部分,来提升网络模型中不同尺寸特征图、不同层的特征之间的信息利用率,有助于学习多尺度缺陷目标的特征;在Neck部分的高层结构中使用 GhostSPPCSPC 模块,避免信息冗余,进一步减小模型计算量与模型参数,加快模型训练和收敛速度。
Smart Images

Figure CN117911399B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision target detection technology, and in particular to a lightweight, multi-scale surface defect detection method for aluminum profiles based on deep learning. Background Technology
[0002] Aluminum, due to its high machinability, good corrosion resistance, and low density, is an important non-ferrous metal in production and daily life. However, during the production of aluminum profiles, various factors such as processes and molds can lead to different types of surface defects, including exposed surfaces, orange peel texture, and pitting. These defects negatively impact the lifespan, strength, and aesthetics of the aluminum profiles. To ensure product quality and enhance brand reputation, manual quality inspection is often necessary. However, the surface of aluminum profiles naturally contains textures that are difficult to distinguish from defects. Traditional manual visual inspection is laborious and cannot accurately identify surface defects in a timely manner, making it difficult to control the efficiency of quality inspection.
[0003] With the continuous advancement of semiconductor and electronic technologies, computer hardware performance has significantly improved, and the field of deep learning has particularly benefited from this increase in computing power, especially in image processing tasks. Deep learning-based object detection methods can be broadly categorized into anchor-based methods and anchor-free methods. Anchor-based methods are further divided into one-stage and two-stage detection algorithms. Generally, two-stage detection algorithms outperform one-stage algorithms in accuracy, but the latter has advantages in detection speed and efficiency.
[0004] Currently, the YOLOv7 target detection algorithm is frequently used in industry for defect detection. However, due to the diverse types of defects on aluminum profile surfaces, their significant variations in length-to-width ratios, and the existence of some very small defect sizes, the YOLOv7 algorithm's performance in aluminum profile surface defect detection is unsatisfactory, exhibiting high false negative rates and low detection accuracy. Industry defect data often exhibits class imbalance, meaning the number of negative samples (defect-free) far exceeds the number of defective samples. Furthermore, acquiring large-scale defective industrial image data is an expensive and time-consuming task. This significant imbalance in the positive-to-negative sample ratio may cause the model to overemphasize normal samples, resulting in poor defect detection performance.
[0005] Existing technologies for detecting surface defects in aluminum profiles face numerous challenges, such as a lack of defect samples, low defect visibility, and irregular shapes. These factors make it difficult for many existing methods to simultaneously meet the requirements of high precision and high speed. Furthermore, since industrial defects are generally accidental, their shapes, areas, and sizes are often varied and irregular. There are also challenges related to the similarity of characteristics between different types of defects and their indistinguishability from the background. Summary of the Invention
[0006] The purpose of this invention is to provide a lightweight, multi-scale aluminum profile surface defect detection method to address the shortcomings of existing technologies. It employs a convolutional kernel attention module to help adapt the receptive field size, thereby achieving accurate localization of the defect target. It uses a bidirectional feature fusion method to connect low-level and high-level features, fusing image features of different sizes to enable the network to learn multi-scale defects more comprehensively. The trained model is then subjected to INT8 mixed-precision quantization and deployed to the TensorRT platform for acceleration. This method involves manually annotating the collected aluminum profile surface images and categorizing defects into ten types: non-conductive, scratches, corner defects, orange peel, bottom defects, splattering, paint bubbles, pitting, discoloration, and dirt spots. Next, data augmentation is performed on the collected dataset to expand its size. Training is then conducted on the corresponding dataset, replacing ordinary convolutions with depthwise separable convolutions to significantly reduce convolution parameters. During feature extraction, a convolution kernel attention module is used to help adapt the receptive field size, thus achieving accurate localization of defect targets. A bidirectional feature fusion approach connects low-level and high-level features, fusing image features of different sizes to enable the network to learn multi-scale defects more comprehensively. A Ghost module is used for spatial pyramid pooling at the detection head to reduce the computational resources required by the network and improve the speed of candidate box generation. Finally, to ensure real-time model inference, the trained model is subjected to INT8 mixed-precision quantization and deployed to the TensorRT platform for acceleration. This invention proposes a lightweight multi-scale aluminum profile surface defect detection method based on YOLOv7, which improves the detection effect of aluminum profile defects while ensuring real-time performance, thus contributing to increased factory productivity. The method is simple and effective. While ensuring high accuracy of model detection output, it also reduces the computational load of the model, greatly meeting the real-time requirements of the industrial field and showing promising application prospects.
[0007] The specific technical solution to achieve the purpose of this invention is: a lightweight multi-scale aluminum profile surface defect detection method, characterized by employing a convolutional kernel attention module to help adaptively adjust the receptive field size, thereby achieving accurate localization of the defect target. It utilizes bidirectional feature fusion to connect low-level and high-level features, fusing image features of different sizes to enable the network to learn multi-scale defects more comprehensively. The trained model is then subjected to INT8 mixed-precision quantization and deployed to the TensorRT platform for acceleration. The specific steps for aluminum profile surface defect detection include: Step a: Image Acquisition A dataset of surface defect images of aluminum profiles was created, and the defect images were labeled into 10 defect types: non-conductive, scratches, corner defects, orange peel, bottom defects, spraying, paint bubbles, pitting, discoloration, and dirt spots. The labels were then converted to YOLO format.
[0008] Step b: Data preprocessing Data augmentation processing is performed on the surface defect images of aluminum profiles. Random operations such as flipping, rotating, cropping, adjusting brightness, and Gaussian blurring are used to randomly process the data, thereby expanding the dataset size. Mosaic-4 and CutMix data augmentation are then performed when loading the data to improve the model's generalization ability and performance by increasing the diversity of the dataset.
[0009] Step c: Image segmentation Ensure that each image has a corresponding label indicating the location and type of the defect, and divide the dataset into training, validation, and test sets.
[0010] Step d: Train the model Iterative training is performed using the improved YOLOv7 algorithm. Training one epoch is completed after all batches are trained. The training is then repeated batch-wise on the divided training sets until the network converges. Training ends, and the network parameters are saved to obtain the final trained aluminum surface defect detection model.
[0011] Step e: Model export The obtained aluminum profile surface defect detection model is exported as an ONNX format. ONNX is a framework-independent model expression. This format is used as an intermediate model file to prepare for subsequent INT8 mixed-precision training and quantization, and deployment to the TensorRT backend for acceleration.
[0012] Step f: Model calibration, quantification, and evaluation Post-Training Quantization (PTQ) is performed using the exported ONNX format intermediate model file to prepare the calibration dataset and the trained model. This invention uses the validation set partitioned in step c as the calibration set. The calibration data is mainly used to calibrate and evaluate the quantized model. After image resizing and batch normalization preprocessing, the calibration set data is fed into the model for forward propagation. Simultaneously, the observer tracks the weights and activation values and estimates the dynamic range of the network parameters on this dataset. Based on the recorded dynamic range, the quantization parameters scale and zero point are calculated; these parameters are collectively referred to as q-params, which are used to quantize the network. This invention freezes the weights of the decoding modules after the output layers of the three different sized detector heads in the YOLOv7 network, without performing INT8 quantization, maintaining the accuracy of the fp32 data. The final model is then deployed to the TensorRT platform for acceleration.
[0013] Step g: Analyze the location and type of defects in the image and visualize them on the original image. The pre-trained aluminum surface defect detection model is deployed to a computer or server. For each image in the test set, image resizing and batch normalization preprocessing are performed to ensure that the input images meet the model's input requirements. The preprocessed images are then input into the trained model, and the model is run to obtain prediction results. Based on the model's output, the location and type of defects in each image are analyzed. The location and type of defects are visualized on the original images to better understand and analyze the detection results.
[0014] The specific operation method for step b is as follows: b-1: Copy and paste images of aluminum surface defects of different sizes and defects onto a new background image. This increases the background diversity during model training, making the model more robust and adaptable to different detection environments.
[0015] b-2: Apply Gaussian blur to images of aluminum surface defects to simulate depth of field or motion blur by reducing image details. This helps the model learn to identify defects at different focus levels.
[0016] b-3: Change the brightness of the aluminum surface defect image to simulate images under different lighting conditions, so that the model can better identify defects in different lighting environments.
[0017] b-4: Rotating images increases the diversity of data, which helps the model learn to identify defects from different perspectives.
[0018] b-5: Cropping the image changes the position and relative size of the defective object in the image, thus providing training samples at different scales.
[0019] b-6: Move the position of the defective object in the image to enhance the data information at different locations.
[0020] b-7: By flipping the image horizontally or vertically, a mirror version of the defective object can be created, improving the model's ability to learn and recognize mirror-symmetric defects.
[0021] b-8: Randomly select 4 images and stitch them together using Mosaic-4 to create a new image. Mosaic-4 is a data augmentation technique that is often used in object detection networks to improve detection accuracy.
[0022] The specific operation method for step d is as follows: d-1: The K-means++ algorithm is used to cluster the width and height of the ground truth bounding boxes in the training set label information. Based on the clustering results, the basic size and aspect ratio of the anchors in the NECK part of the YOLOv7 network can be adjusted.
[0023] d-2: Replace the 3x3 ordinary convolutions in the ELAN module of the YOLOv7 network with DWConv depthwise separable convolutions.
[0024] d-3: By introducing the Selective Kernel Network attention module into the YOLOv7 backbone network to adapt the receptive field, SKNet introduces a gating unit to determine the size of the convolutional kernel used at each location, thereby achieving effective capture of features at different scales.
[0025] d-4: Introducing the BiFPN module into the YOLOv7 network, which bidirectionally fuses feature maps of different sizes extracted by the backbone network, helps to capture multi-scale targets and comprehensively learn the features of the input image.
[0026] d-5: The GhostSPPCSPC structure is adopted in the YOLOv7 detection head module to avoid information redundancy, further reduce the model's computational load and parameters, and accelerate model training and convergence.
[0027] d-6: Optimize the loss function by using SIOU as the coordinate regression loss function. SIOU reduces the impact of bounding box size changes on the localization loss by introducing a scale-invariant term, thereby reducing the total number of degrees of freedom and further improving the model training effect and network convergence speed.
[0028] The specific operation method for step e is as follows: Use the `torch.onnx.export` function to convert a PyTorch model to ONNX format. The following are the basic steps and precautions for the conversion: e-1: Install necessary libraries: Ensure that the ONNX and PyTorch libraries are installed.
[0029] e-2: Prepare the model and input data: Prepare the network model trained in step (4) and load it into memory. Prepare the data for the input image of the aluminum profile defect detection model. The dimension of the input data is 1x3x512x512, which is consistent with the model input.
[0030] e-3: Calling the export function: Use the torch.onnx.export function to export the model: torch.onnx.export(model, args, f, export_params=True, verbose=False, training=False, input_names=None, output_names=None, do_constant_folding=True, dynamic_axes=None, opset_version=9) model: The PyTorch model to be exported.
[0031] args: The input parameters of the model, which can be tuples or tensors. If it is a tuple, the last element should be a dictionary. f: The filename used to save the ONNX model.
[0032] export_params: Whether to export the model's parameters. The default value is True.
[0033] verbose: Whether to print detailed information, defaults to False.
[0034] training: Whether to set the model to training mode, the default is False.
[0035] input_names and output_names: These are lists of names for the input and output, respectively. If not specified, they will be generated automatically.
[0036] do_constant_folding: Whether to perform constant folding optimization, the default is True.
[0037] dynamic_axes: A list of dynamic axes. If not specified, they will be inferred automatically.
[0038] opset_version: ONNX operation set version, the default is 9.
[0039] e-4: Check and Verification: After the conversion is complete, use the ONNX library to load the generated .onnx file to verify that the model has been converted correctly and to ensure that it can run on other deep learning frameworks.
[0040] Compared with the prior art, the present invention has the following beneficial technical effects and significant technical progress: 1) This invention presents a lightweight network for multi-scale defect detection based on improved YOLOv7. When constructing the detection model, the YOLOv7 network contains a large number of ELAN structures. The 3x3 ordinary convolutions in the ELAN structures are replaced by depthwise separable convolutions (DWConv), which can reduce the computational cost of the model and remove redundant information. The Selective Kernel Networks attention mechanism is introduced into the backbone network to adaptively adjust the receptive field size and reduce the weight of unimportant information. The BiFPN bidirectional feature pyramid network structure is used as the Neck part of the network to improve the information utilization between feature maps of different sizes and features of different layers in the network model, which helps to learn the features of multi-scale defect targets. The GhostSPPCSPC module is used in the high-level structure of the Neck part to avoid information redundancy, further reduce the computational cost and model parameters, and accelerate the training and convergence speed of the model.
[0041] 2) This invention introduces SIoU as the coordinate regression loss function. During YOLOv7 training, the localization loss function penalizes the deviation between the model's predicted bounding boxes and the ground truth bounding boxes. Traditional IoU (Intersection over Union) measures the overlap between two bounding boxes, but it is not directly used as a loss function because it is not differentiable. To address this issue, YOLOv7 introduced CIoU (Complete Intersection over Union), which considers not only the overlapping area of the bounding boxes but also the distance between the center points and the aspect ratio, making gradient updates more accurate. This invention introduces an improved version of CIoU, SIoU (Scale-Invariant Intersection over Union), which further optimizes this by introducing a scale-invariant term to reduce the impact of bounding box size changes on the localization loss, thereby reducing the total number of degrees of freedom and improving model training performance and network convergence speed.
[0042] 3) This invention improves the NMS algorithm in model inference tasks to a Soft-NMS algorithm. Soft-NMS employs a more flexible score reset strategy. When processing overlapping bounding boxes, Soft-NMS does not completely eliminate low-scoring boxes, but rather reduces their scores based on their IOU value with the highest-scoring box. This means that the box scores decrease in a continuous manner, rather than being binarized and eliminated or retained as in NMS.
[0043] 4) This invention uses the PTQ post-training quantization method to perform INT8 mixed-precision quantization on the trained aluminum profile defect detection model, and freezes the decoding module after the output of the first 3 layers of detection features. While ensuring the high accuracy of the model detection output, it also takes into account the reduction of the model's computational load, ensuring that the network proposed in this invention meets the real-time requirements of the industrial field. Attached Figure Description
[0044] Figure 1 This is a flowchart of the present invention; Figure 2 This is a schematic diagram of the GhostSPPCSPC module structure; Figure 3 This is a schematic diagram of the GhostConv module structure; Figure 4 This is a schematic diagram of the DW-ELAN module structure. Detailed Implementation
[0045] The invention will be further described below with reference to specific examples and accompanying drawings. Example
[0046] See Figure 1 This invention provides a lightweight, multi-scale surface defect detection method for aluminum profiles based on YOLOv7, specifically including the following steps: (1) Collect images of surface defects of aluminum profiles, label the images, and label the defect targets as 10 categories: non-conductive, scratches, corner bottom leakage, orange peel, bottom leakage, spraying, paint bubbles, pitting, discoloration, and dirt spots.
[0047] (2) The data of surface defects of aluminum profiles is expanded by performing random up-down-left-right flipping, rotation, cropping, brightness adjustment and Gaussian blurring. The new images and the synchronously adjusted annotation data are added to the original dataset.
[0048] (3) Classify the dataset into training set, validation set and test set.
[0049] (4) The K-means++ algorithm is used to cluster the width and height of the true bounding boxes in the training set label information. Based on the clustering results, three sets of anchor box data are obtained. In this implementation, the anchor box data are: [23,13, 102,41, 267,29],[510,23, 157,143, 508,67],[508,115, 503,174, 492,282].
[0050] (5) Load the training set data, perform image preprocessing on the training set data, randomly select 16 images for Mosaic stitching, which randomly crops and stitches the 16 images into a new image. In this implementation, the model has a fixed input size of 512x512. In this implementation, the preprocessed image is resized and padded to adjust the image to a size of 512x512, and the pixel value is batch normalized.
[0051] (6) Construct a YOLOv7 model and improve the YOLOv7 model. The improved YOLOv7 model includes a separable convolutional backbone network, a convolutional kernel attention mechanism introduced into the backbone network, a neck bidirectional feature fusion network, and the GhostSPPCSPC module used in the detection head.
[0052] (7) Set training parameters, including image size, number of iterations, number of training set samples, weight decay coefficient, maximum learning rate, and learning rate descent method. Iterative training is performed using the improved YOLOv7 algorithm. Training one epoch is completed after all batches are trained. In this embodiment, the input image size is set to [640, 640, 3], a total of 300 epochs are trained, the batch size is set to 16, and the training ends after 300 iterations of model parameter updates. In this embodiment, the first 3 epochs are set for warm-up, the base learning rate for warm-up is set to 0.1, the momentum coefficient for warm-up is 0.8, the momentum coefficient is set to 0.937, the weight decay coefficient is 0.0005, the learning rate descent method is cosine annealing, the model initialization learning rate is 0.01, and the maximum learning rate is set to 0.1.
[0053] (8) Train the improved YOLOv7 network using the training set and evaluate the model's performance on the validation set. This implementation uses the stochastic gradient descent (SGD) optimization algorithm for parameter updates. The hyperparameter tuning operation in this implementation is based on performance metrics during training, such as accuracy, recall, and F1 score, to adjust the network's learning rate, batch size, and number of iterations to improve the model's training efficiency and detection accuracy, ultimately obtaining the values in step (7).
[0054] (9) Export the obtained aluminum profile surface defect detection model as ONNX format. ONNX is a framework-independent model expression. Use this format as an intermediate model file to prepare for the next step of training and quantization after INT8 mixed precision and deployment to the TensorRT backend for acceleration.
[0055] (10) Post-Training Quantization (PTQ) is performed using the exported ONNX format intermediate model file to prepare the calibration dataset and the trained model. In this invention, the validation set divided in step (3) is used as the calibration set. The calibration data is mainly used to calibrate the quantized model and evaluate the model. After the calibration set data undergoes image resizing and batch normalization preprocessing, it is fed into the model for calculation and forward propagation. At the same time, the observer tracks the weights and activation values and estimates the dynamic range of the network parameters under this dataset. The quantization parameters scale and zero point are calculated based on the recorded dynamic range. These parameters are collectively referred to as q-params. The q-params are used to quantize the network. In this invention, the weights of the decoding modules after the output layers of the three different sizes of detector heads in the YOLOv7 network are frozen and no INT8 quantization is performed to maintain the accuracy of the fp32 data. The final model is then deployed to the TensorRT platform for acceleration.
[0056] See Figures 2-4 The three detection heads of different sizes are GhostSPPCSPC module, GhostConv module and DW-ELAN module.
[0057] (11) Deploy the trained aluminum surface defect detection model to a computer or server for practical application. In this implementation, the image preprocessing function is written into the actual project pipeline. Real-time highlights of aluminum profile production are captured by image acquisition equipment. After image preprocessing, the images are input into the deployed model for inference to obtain prediction results. Based on the model output, the location and type of defects in each image are parsed out, and the location and type of defects are visualized on the original image to better understand and analyze the detection results.
Claims
1. A lightweight, multi-scale surface defect detection method for aluminum profiles, characterized in that, This method employs a convolutional kernel attention module to help adapt the receptive field size, thereby achieving accurate localization of defect targets. It utilizes bidirectional feature fusion to connect low-level and high-level features, fusing image features of different sizes to enable the network to learn multi-scale defects more comprehensively. The trained model is then subjected to INT8 mixed-precision quantization and deployed to the TensorRT platform for acceleration. The specific steps for detecting surface defects in aluminum profiles include: Step a: Image Acquisition A dataset of surface defect images of aluminum profiles was created. The defect images were categorized into ten types: non-conductive, scratches, corner exposure, orange peel, exposed bottom, splatter, paint bubbles, pitting, discoloration, and dirt spots. The labels were then converted to YOLO format. Step b: Data preprocessing Random processing of aluminum profile surface defect images was performed by randomly flipping, rotating, cropping, adjusting brightness, and Gaussian blurring operations in all directions to expand the dataset size. Mosaic-4 and CutMix data augmentation were performed when loading the data to improve the model's generalization ability and feature extraction ability by increasing the diversity of the dataset. Step c: Image segmentation Ensure that each aluminum profile surface defect image has a corresponding label indicating the location and type of the defect, and divide the dataset according to the training set, validation set, and test set; Step d: Prepare a surface defect detection model for aluminum profiles The YOLOv7 algorithm was improved by adding a convolutional kernel attention mechanism to the backbone network, introducing DWConv to the ELAN structure in the backbone network for lightweight structural design, changing the multi-scale feature fusion mechanism of the neck network structure to a bidirectional feature fusion structure BiFPN, and enhancing the coordinate regression loss function to a SIOU function. This resulted in an aluminum profile surface defect detection model, which was then loaded into memory. Step e: Train the model The aluminum profile surface defect detection model constructed in step d is iteratively trained. After all batches are trained, it means that one epoch of training has been completed. At this time, the training set divided by batch is repeated until the network converges. After training, the network parameters are saved to obtain the final trained aluminum profile surface defect detection model. Step f: Model export The obtained aluminum profile surface defect detection model is exported as an ONNX format. ONNX is a frame-independent model expression, which is used as an intermediate model file. Step g: Model calibration and quantization The intermediate file of the exported ONNX format model is subjected to post-training quantization PTQ. The validation set divided in step c is used as the calibration set. After image resizing and batch normalization preprocessing, it is fed into the aluminum surface defect detection model for forward propagation. At the same time, the observer tracks the weights and activation values and estimates the dynamic range of the network parameters under this dataset. The quantization parameters scale and zero point are calculated based on the recorded dynamic range, and the network is quantized using these parameters. The quantization network freezes the weights of the decoding module after the output layer of the three detection heads of different sizes in the Yolov7 network, without performing INT8 quantization, to maintain the accuracy of fp32 data. The final aluminum surface defect detection model is then deployed to the TensorRT platform for acceleration. Step h: Analyze the location and type of defects in the image and visualize them on the original image. The trained aluminum surface defect detection model is deployed to a computer or server. For each image in the test set, image size adjustment and batch normalization preprocessing operations are performed. The preprocessed images are input into the trained aluminum surface defect detection model, and the model is run to obtain prediction results. Based on the model output, the location and type of defects in each image are parsed, and the location and type of defects are visualized on the original image to facilitate understanding and analysis of the detection results. The specific operation of step d is as follows: d-1: Use the K-means++ algorithm to cluster the width and height of the ground truth bounding boxes in the training set label information, and adjust the basic size and aspect ratio of the anchors in the NECK part of the YOLOv7 network according to the clustering results; d-2: Replace the 3x3 ordinary convolutions in the ELAN module of the YOLOv7 network with DWConv depthwise separable convolutions; d-3: By introducing the Selective Kernel Network attention module into the YOLOv7 backbone network to adapt the receptive field, SKNet introduces a gating unit to determine the size of the convolutional kernel used at each location, thereby achieving effective capture of features at different scales. d-4: Introduce the BiFPN module into the YOLOv7 network to fuse feature maps of different sizes extracted by the backbone network in a bidirectional feature fusion manner; d-5: The GhostSPPCSPC structure is used in the Neck network module of the YOLOv7 network to accelerate model training and convergence. d-6: Using SIOU as a better solution for the coordinate regression loss function, a surface defect detection model for aluminum profiles is obtained. SIOU reduces the impact of bounding box size changes on the positioning loss by introducing a scale invariant term, thereby reducing the total number of degrees of freedom and improving the model training effect and network convergence speed. d-7: Load the aluminum profile surface defect detection model constructed above into memory for future use; The three different sized detection heads in the YOLOv7 network are the GhostSPPCSPC module, the GhostConv module, and the DW-ELAN module.
2. The lightweight multi-scale aluminum profile surface defect detection method according to claim 1, characterized in that, The specific data preprocessing steps in step b are as follows: b-1: Copy and paste images of aluminum surface defects of different sizes and defects onto a new background image; b-2: Apply Gaussian blur to images of aluminum surface defects to simulate depth of field or motion blur by reducing image details; b-3: Adjust the brightness of the aluminum surface defect image to enable the model to better identify defects under different lighting conditions; b-4: Increase the diversity of data by rotating images, enabling the model to learn to identify defects from different perspectives; b-5: Crop the image to change the position and relative size of the defective object in the image, so as to provide training samples at different scales; b-6: Move the position of the defective object in the image to enhance the information at different locations; b-7: By horizontally or vertically flipping the image to create a mirrored version of the defective object, the model learns to recognize mirror-symmetric defects; b-8: The Mosaic-4 method is used to stitch four images into one new large image, which effectively increases the batch size to improve the robustness and detection accuracy of the model.
3. The lightweight multi-scale aluminum profile surface defect detection method according to claim 1, characterized in that, Step e uses the torch.onnx.export function to convert the PyTorch model into ONNX format. The specific export steps are as follows: e-1: Install ONNX and PyTorch libraries; e-2: Load the trained aluminum surface defect detection model into memory, and use random numbers to generate data of size 1x3x512x512 to simulate the input data of the aluminum surface defect detection model, which is used as the second input parameter in the function of step e-3; e-3: Use the torch.onnx.export function to export the aluminum surface defect detection model: `torch.onnx.export(model, args, f, export_params=True, verbose=False, training=False, input_names=None, output_names=None, do_constant_folding=True, dynamic_axes=None, opset_version=9);` Where `model` is the exported PyTorch model; `args` are the input data tuples or tensors of the model; if it's a tuple, the last element should be a dictionary; `f` is the filename for saving the ONNX model; `export_params` specifies whether to export the model's parameters (default is True); `verbose` specifies whether to print detailed information (default is False); `training` specifies whether to set the model to training mode (default is False); `input_names` and `output_names` are lists of input and output names, respectively; `do_constant_folding` specifies whether to perform constant folding optimization (default is True); `dynamic_axes` is a list of dynamic axes (automatically inferred if not specified); and `opset_version` is the ONNX operation set version (default is 9). e-4: Use the ONNX library to load the generated .onnx file, verify that the aluminum surface defect detection model has been correctly converted, and ensure that it can run on other deep learning frameworks.
Citation Information
Patent Citations
Fabric defect detection method based on image reconstruction
CN120147282A