Production line aluminum alloy ingot surface defect detection method, device and system and storage medium
By using the YOLOv5 detection model and optimized anchor frame, combined with attention mechanism and data enhancement technology, the problem of low manual judgment accuracy in surface defect detection of aluminum alloy ingots is solved, and fast and accurate defect detection and improved detection efficiency are achieved.
Patent Information
- Application Number
- CN202411736427.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-21
AI Technical Summary
In the prior art, the surface defect detection of aluminum alloy ingots mainly relies on manual judgment, and there are problems that it is difficult to ensure the detection accuracy and the detection quality are difficult to maintain for a long time.
The YOLOv5 detection model is adopted, combined with the K-means++ algorithm to optimize the initial anchor box, integrate the attention mechanism dynamic detection head Dyhead, and enhance the data set through the Mixup and Mosaic data augmentation algorithm, introduce Focal loss function and non-maximum suppression to achieve rapid and accurate detection of surface defects of aluminum alloy ingots.
It realizes rapid and accurate detection of surface defects of aluminum alloy ingots, improves detection accuracy and efficiency, is suitable for industrial deployment, and can effectively detect small defects.
Smart Images

Figure CN119671975A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of aluminum alloy ingot detection, and in particular relates to a method and device, a system, and a storage medium for detecting surface defects of aluminum alloy ingots in a production line. Background Art
[0002] Aluminum alloy is one of the most common raw materials. It is light and has sufficient strength and corrosion resistance. It is widely used in various fields. With the improvement of metallurgical production technology, users have also put forward higher requirements for the surface quality of aluminum alloy ingots. Aluminum is usually refined and cast into aluminum alloy ingots for subsequent production. During the casting process of aluminum alloy ingots, due to the uncertainty of the production environment, some aluminum alloy ingots may have various surface defects due to factors such as incomplete slag removal, slag falling during slag removal, and uneven cooling of aluminum liquid. These defects affect the appearance and quality of the product, and then affect the price of aluminum alloy ingots and corporate competition. Therefore, it is necessary to efficiently detect the surface defects of aluminum alloy ingots.
[0003] At present, most factories mainly use manual judgment and selection for aluminum alloy ingots with surface defects. The aluminum alloy ingot surface defect detection scheme based on manual selection has many shortcomings. For example, manual inspection is mainly based on experience, and there is no practical and objective standard. The detection accuracy is difficult to guarantee, and manual inspection cannot consistently guarantee the detection quality for a long time. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method and device, system, and storage medium for detecting surface defects of aluminum alloy ingots on a production line, which can quickly detect the type and location of defects to meet the needs of rapid and accurate detection of aluminum alloy ingot production lines.
[0005] To achieve the above object, the present invention adopts the following technical solution:
[0006] A method for detecting surface defects of aluminum alloy ingots in a production line, comprising:
[0007] Collecting aluminum alloy ingot surface defect image dataset;
[0008] YOLOv5 is selected as the detection model, and the K-means++ algorithm is used to optimize the initial anchor box according to the application scenario;
[0009] Improve the YOLOv5 detection model by accelerating reasoning and integrating the attention mechanism dynamic detection head Dyhead;
[0010] The Mixup and Mosaic data enhancement algorithms are used to enhance the data set and train the improved YOLOv5 detection model. The Focal loss function and non-maximum suppression are introduced during training.
[0011] The trained model is used to detect the surface defect images of aluminum alloy ingots to obtain the type confidence and location information of the defects in the images.
[0012] Preferably, a multi-branch structure is used to accelerate the reasoning of the YOLOv5 detection model, wherein the multi-branch structure includes six branches: BN fusion, branch merging, convolution sequence merging, depth stitching merging, mean pooling conversion and multi-scale convolution conversion.
[0013] Preferably, DyHead combines the three self-attention mechanisms into the detection head, redefines the four-dimensional tensor L×H×W×C as L×S×C to obtain a three-dimensional tensor, and uses scale-aware attention, space-aware attention, and task-aware attention in the three dimensions of scale L, space S, and channel C, respectively.
[0014] The present invention also provides a production line aluminum alloy ingot surface defect detection device, comprising:
[0015] An acquisition module is used to collect a data set of surface defect images of aluminum alloy ingots;
[0016] The first processing module is used to select YOLOv5 as the detection model and use the K-means++ algorithm to optimize the initial anchor frame according to the application scenario;
[0017] The second processing module is used to accelerate the reasoning of the YOLOv5 detection model and integrate the attention mechanism dynamic detection head Dyhead;
[0018] The training module is used to enhance the data set using the Mixup and Mosaic data enhancement algorithms and train the improved YOLOv5 detection model, and introduce the Focal loss function and non-maximum suppression during training;
[0019] The detection module is used to detect the surface defect images of aluminum alloy ingots using the trained model to obtain the type confidence and location information of the defects in the image.
[0020] Preferably, a multi-branch structure is used to accelerate the reasoning of the YOLOv5 detection model, wherein the multi-branch structure includes six branches: BN fusion, branch merging, convolution sequence merging, depth stitching merging, mean pooling conversion and multi-scale convolution conversion.
[0021] Preferably, DyHead combines the three self-attention mechanisms into the detection head, redefines the four-dimensional tensor L×H×W×C as L×S×C to obtain a three-dimensional tensor, and uses scale-aware attention, space-aware attention, and task-aware attention in the three dimensions of scale L, space S, and channel C, respectively.
[0022] An embodiment of the present invention also provides a production line aluminum alloy ingot surface defect detection system, comprising: a memory and a processor, wherein the memory stores a computer program run by the processor, and the computer program executes a production line aluminum alloy ingot surface defect detection method when run by the processor.
[0023] An embodiment of the present invention further provides a storage medium having a computer program stored thereon, and the computer program executes a method for detecting surface defects of aluminum alloy ingots in a production line when the computer program is run.
[0024] Compared with the prior art, the present invention has the following beneficial effects:
[0025] The present invention collects surface defect images of aluminum alloy ingots on-site, expands the data by using image expansion methods such as affine transformation and translation expansion, and uses annotation tools to annotate the data set to obtain a surface defect data set of aluminum alloy ingots, thereby solving the problem that there are few studies on surface defect detection of aluminum alloy ingots and no public data set.
[0026] According to the characteristics of the self-built data set (many slender defects and small defects), the K-means++ algorithm was used to optimize the initial anchor frame of the YOLOv5 algorithm, solving the problem that the original anchor frame of YOLOv5 was obtained by clustering during the training process of the COCO data set or the VOC data set, and was not applicable to the application scenario of aluminum alloy ingots.
[0027] The present invention adopts a multi-branch design in the network extraction trunk, which is conducive to the extraction of multi-scale image features. It also combines the structural reparameterization method to convert the multi-branch module into a single-channel network structure during model inference, which reduces the inference time and is more conducive to industrial deployment. When checking the head position, it combines multiple attention mechanisms such as scale-aware attention, space-aware attention, and task-aware attention to enhance the detection of small defects.
[0028] When training the detection model, the present invention adopts Mixup and Mosaic data enhancement algorithms. Mixup randomly mixes images and labels, and Mosaic randomly selects four pictures, performs random jitter, and then stitches the four pictures into one picture to enrich the training data. Soft maximum suppression (Soft_NMS) is introduced and combined with EIoU, the EIoU_Soft_NMS algorithm is proposed to replace the non-maximum suppression (NMS) of the original network, thereby reducing the missed detection and false detection when the object is occluded, and improving the detection accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0030] Figure 1 A flowchart of a method for detecting surface defects of aluminum alloy ingots on a production line based on deep learning provided by the present invention;
[0031] Figure 2 This is an experimental comparison of the four models YOLOv4 / 5 / 7 / 8 on the aluminum alloy ingot surface defect dataset;
[0032] Figure 3 The clustering effect of anchor boxes on surface defects of aluminum alloy ingots by K-means++ algorithm;
[0033] Figure 4 This is a network structure diagram of the surface defect detection method of aluminum alloy ingots in the production line of the present invention;
[0034] Figure 5 The connection mode of DyHead block-scale perception attention, space perception attention, and task perception attention;
[0035] Figure 6 Comparison chart of loss functions used during training;
[0036] Figure 7 The learning thermal map comparison of the aluminum alloy ingot surface defect detection method of the present invention and other models. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0038] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0039] Embodiment 1:
[0040] The problem of high cost and subjective factors in manual inspection, and the difficulty of the current network in balancing detection speed and accuracy. The present invention uses the current mainstream YOLO algorithm as the detection framework, and adopts the kmeans++ clustering algorithm to optimize the initial anchor frame for the aluminum alloy ingot scenario. Through the use of structural re-parameterization, the decoupling of the training time and reasoning time architectures is achieved. During training, a multi-branch architecture is used to enhance feature learning, and during reasoning, it is converted to a single branch to achieve fast reasoning; the attention mechanism is combined with the detection head to improve the detection accuracy of small target defects. Finally, during training, a data enhancement algorithm is introduced to increase the diversity of data, and a Focal loss function is introduced to solve the problem of data imbalance caused by a small number of burr samples. Based on the above, an embodiment of the present invention provides a surface defect detection method for aluminum alloy ingots on a production line based on deep learning. As Figure 1 As shown, the following steps are included:
[0041] S1. Collect surface defect images of aluminum alloy ingots on the aluminum alloy ingot casting line, preprocess the images and label the defect categories, divide the defect data set into training set and test set.
[0042] S11: Collect surface defect images on the aluminum alloy ingot production line, expand the data set through data enhancement methods such as brightness enhancement, contrast enhancement, image rotation, image flipping, etc., and reduce image resolution to reduce computational dependence;
[0043] S12: Use the LabelImg image annotation tool to annotate the surface defects of aluminum alloy ingots. Select the PASCAL VOC format to save the annotation data. YOLO and CreateML formats are also supported. Each annotated image generates an XML file containing detailed information about the location, size, and category of the defects in the aluminum alloy ingot image. Finally, all images are divided into a test set and a training set in a ratio of 1:9.
[0044] S2. YOLOv5 was selected as the detection algorithm, and the K-means++ algorithm was used to optimize the initial anchor box according to the application scenario.
[0045] S21: Considering that the two-stage target detection algorithm has relatively high detection accuracy, but slow detection speed, it is not suitable for scenarios with high real-time requirements. The present invention adopts a one-stage target detection strategy. A comparative test was conducted on the YOLOv4 / 5 / 7 / 8 series algorithms. Finally, it was found that the surface defect detection effect of aluminum alloy ingots on the YOLOv5 algorithm was the best. Figure 2 As shown, the YOLOv5 algorithm is used as the detection framework;
[0046] S22: Based on YOLOv5, the K-means++ algorithm is used to optimize the initial anchor frame for the special application scenario of the aluminum alloy ingot surface. The implementation process includes the following steps:
[0047] (1) Randomly select one of all bboxes as the cluster center;
[0048] (2) Calculate the distance between each bboxes and the nearest existing cluster center, the distance is L (x) , then the probability of each bboxes being selected as the next cluster center is Finally, the next cluster center is selected according to the probability, and the process is repeated until the set K cluster centers are selected;
[0049] (3) Calculate the distance between each bboxes and each cluster center, and then divide the bboxes into the class closest to it;
[0050] (4) Update the cluster center and calculate the mean of all bboxes in each class as the new cluster center;
[0051] (5) Repeat steps 3 and 4 until the cluster center no longer changes or the change meets the termination condition, and the final clustering result is obtained.
[0052] The initial anchor frame of the original YOLOV5 target detection network is obtained by clustering during the training process of the COCO dataset or the VOC dataset. For the aluminum alloy ingot surface defect dataset, the defect target types are relatively few, and the flash defects are generally slender. The original anchor size is not suitable for the detection of slender flash defects on the surface of aluminum alloy ingots. In order to determine the optimal anchor size, the K-Means++ algorithm of the present invention performs preliminary anchor size clustering on the aluminum alloy ingot surface defect dataset. The clustering effect is shown in the figure below. Figure 3 As shown in Table 1, the best initial anchor box is obtained.
[0053] Table 1
[0054]
[0055] S3, using the re-parameterization method to accelerate model reasoning, integrating the attention mechanism dynamic detection head Dyhead to improve the model's small target defect recognition accuracy. The network structure is as follows Figure 4 As shown, specifically including;
[0056] S31: Using the reparameterization method to accelerate model reasoning, the present invention designs a multi-branch structure, which includes six branches: BN fusion, branch merging, convolution sequence merging, deep splicing merging, mean pooling conversion and multi-scale convolution conversion.
[0057] Transform I: BN fusion. In deployment mode, in order to speed up the inference, the convolution layer is usually fused with the batch normalization layer. The calculation formula of the batch normalization layer and the convolution layer is:
[0058]
[0059] y=ω*X+b
[0060] Among them, μ represents the mean; σ 2 is the variance; scaling factor γ; bias β; ε is a small number to prevent the denominator from being 0, ω represents the convolution kernel weight, b is the convolution bias, which is generally set to 0 when building the model, and y is the output of the convolution layer, which is the input of the batch normalization layer. The calculation formula is as follows:
[0061]
[0062] After fusion, the original convolution layer and batch normalization layer are represented by only one new convolution operation, where Integrating the batch normalization layer into the convolution is equivalent to making certain modifications to the convolution kernel without increasing the computational complexity of the convolution. At the same time, the computational complexity of the entire batch normalization layer is eliminated. Through conversion one, the first and fourth branches of DBB can be fused into biased 1×1 convolution and k×k convolution.
[0063] Transform II: Branch Merging
[0064] Branch merging utilizes the additive property of convolution. The parameters of two convolutions are merged as follows:
[0065] F′←F (1) +F (2) b′←b (1) +b (2)
[0066] Transform III: Convolutional Sequence Merging
[0067] The continuous 1×1 convolution and k×k convolution can be combined into a single k×k convolution. Here, it is assumed that the convolution groups = 1. If the groups is greater than 1, refer to Transform4. The method of combining these two convolution kernels is also very simple, and the formula is as follows:
[0068]
[0069] Transform IV: Deep stitching and merging
[0070] Inceptioin uses deep splicing to combine different branches. When these branches contain convolutions with the same configuration, we can perform equivalent transformations by splicing the kernel parameters, and transform the convolutions of the two branches into group convolutions. In this case, the convolution sequence of the branch should have the same groups parameter. The combination formula is also very simple, as described below:
[0071] CONCAT(I*F (1) +REP(b (1) ), I*F (2) +REP(b (2) ))=I*F′+REP(b′)
[0072] Transform V: Mean pooling transformation The transformation from mean pooling to convolution is relatively simple. An average pooling with kernel size K and step length s and input channels c can be equivalent to a convolution F′∈R with the same size and step length. C ×C×K×K ,Conversion formula:
[0073]
[0074] Transform VI: Multi-scale convolution transformation
[0075] Put a k h ×k w (k h ≤K,k w ≤K) is converted into a k×k convolution through zero-padding, and the 1×3 and 3×1 convolutions are equivalently converted into 3×3 convolutions.
[0076] The multi-branch and multi-scale ideas of Inception are combined with the idea of re-parameterization. A multi-branch structure is used during training. After training, the trained parameters are linearly combined to calculate the corresponding single-path structure parameters. During inference, only the equivalently transformed structure and corresponding parameters are used, which effectively speeds up the inference speed of the model.
[0077] S32. The dynamic detection head Dyhead with integrated attention mechanism improves the small target defect recognition accuracy of the model. DyHead combines three self-attention mechanisms into the detection head, redefines the four-dimensional tensor L×H×W×C into L×S×C to obtain a three-dimensional tensor, and uses scale-aware attention, space-aware attention, and task-aware attention in the three dimensions of scale L, space S, and channel C respectively.
[0078] (1) Scale-aware attention module, which fuses features of different scales based on their semantic importance. Its expression is as follows.
[0079]
[0080] Where f(·) is a linear function, approximated by 1×1 convolution.
[0081] (2) The spatially aware attention module first uses deformable convolution to learn sparsification and then aggregates cross-level features at the same spatial position. Its expression is as follows.
[0082]
[0083] Where K is the number of sparse sampling locations, p k +Δp k is the self-learning space offset Δp k Focus on the displacement position of a distinguishing area, Δm k is the position p k The important scalars for self-learning at are all learned through the input features of the intermediate levels of F.
[0084] (3) Task-aware attention module, which dynamically turns on or off feature channels to select different tasks, and its expression is as follows.
[0085] π c (F)·F=max(α 1 (F)·F c +β 1 (F),α 2 (F)·F c +β 2 (F)
[0086] Among them, [α 1 ,β 1 ,α 2 ,β 2 ] Τ =θ(·) is a hyperfunction used to learn and control the activation threshold, π L First, global pooling is performed on the L×S dimension for dimensionality reduction, then two fully connected layers, a normalization layer are used, and finally the output is normalized using a shifted sigmoid function.
[0087] Given a feature tensor F∈R L×S×C , the generalized form of self-attention can be described as follows:
[0088] W(F)=π(F)·F
[0089] A naive solution is to use a fully connected layer, but directly learning the attention function in all dimensions will result in too much computation and is impractical due to the high dimensionality problem. Instead, the attention function is converted into three sequential attentions, each focusing on only one dimension:
[0090] W(F)=π C (π S (π L (F)·F)·F)·F)
[0091] where π L , π S , π C Corresponding to the scale, space, and task-aware attention modules, the scale-aware, space-aware, and task-aware DyHead blocks are as follows Figure 5 Connections shown.
[0092] S4. Mixup and Mosaic data enhancement algorithms are used to enhance the data set and train the detection model. Focal loss function and non-maximum suppression method are introduced during training, and combined with EIoU to deal with the sample imbalance problem caused by fewer burr defects.
[0093] The Mixup and Mosaic data enhancement algorithms are used to enhance the data set and train the detection model; the Focal loss function and non-maximum suppression method are introduced during training, and combined with EIoU to obtain the EIoU_Soft_NMS algorithm to deal with the sample imbalance problem caused by fewer burr defects. The expression is as follows:
[0094]
[0095] Soft_NMS is an improvement on the traditional NMS algorithm. The expression is as follows:
[0096]
[0097] Among them, M is the current highest scoring box, s i is the current box to be detected, IoU is the intersection over union ratio, N t is the set threshold, b i is the frame to be processed, b i The larger the IoU with M, the i The more the score drops. However, it only considers the overlapping area of the two boxes, so the EIoU_Soft_NMS algorithm is proposed in combination with EIoU. Not only the overlapping area, but also the center point distance, length, width and side length true difference are considered. The expression is as follows:
[0098]
[0099]
[0100] Among them, b,b gt are the center points of the predicted box and the real box respectively, ρ is the Euclidean distance between the two center points, c is the diagonal length of the minimum circumscribed rectangle containing the predicted box and the real box, and c ω and c h It is the width and height of the smallest enclosing rectangle that covers both boxes.
[0101] Mixup is mainly used for image classification. Two samples are randomly selected from the training samples for simple random weighted summation. The labels of the samples are also weighted summed accordingly. Then the loss is calculated by comparing the predicted results with the labels after weighted summation. The parameters are updated by reverse derivation. The formula is defined as follows:
[0102]
[0103] where x i , x j is the original input vector, y i ,y j is a one-hot label encoding.
[0104] Mosaic data enhancement, this data enhancement method is simply to splice 4 pictures by random scaling, random cropping, and random arrangement. Mosaic can enrich the data set and reduce GPU video memory.
[0105] IoU is the intersection-over-union ratio of the predicted box and the true box, which reflects the detection effect and is insensitive to scale and has scale invariance. However, when the predicted box and the true box do not overlap, IoU = 0 and Loss = 0 are obtained according to the following expression, so the overlap degree of the two boxes cannot be accurately reflected.
[0106]
[0107] L IoU =1-IoU
[0108] YOLOv5 uses CIoU as the bounding box regression loss function on the original basis. The calculation formula is as follows, which takes into account the overlapping area, center point distance, and aspect ratio.
[0109]
[0110] Among them, α is a weight parameter, υ is used to measure the similarity of the aspect ratio, which reflects the difference in aspect ratio, rather than the actual difference between the width and height and their confidence. There is a certain ambiguity and no balance adjustment is made for the difficulty of sample detection. Therefore, the embodiment of the present invention introduces Focal-EIoU as a border regression loss function to solve the ambiguity of the CIoU width and height difference and the problem of balancing the difficulty of sample detection. From the perspective of gradient, high-quality anchor boxes are separated from low-quality anchor boxes, and more attention is paid to high-quality anchor boxes. Among them, γ is a parameter that controls the degree of outlier suppression, and EIoU calculates the difference in width and height on the basis of CIoU instead of the aspect ratio. The calculation expression is as follows.
[0111] L EIoU =1-EIoU
[0112] L Focal-EIoU =IoU γ L EIoU
[0113] In order to verify the performance of Focal-EIoU on this dataset, we compared the CIoU and EIoU results. Figure 6 . Where Loss = box_loss + obj_loss + cls_loss. From Figure 6 It can be clearly seen that the loss of Focal-EIoU is significantly lower than that of CIoU and EIoU, so Focal-EIoU is selected as the loss function of this experiment.
[0114] S5. Use the trained model to detect the surface defect images of aluminum alloy ingots to obtain the type confidence and location information of the defects in the images.
[0115] The present invention uses images of surface defects of aluminum alloy ingots to visualize feature maps, and uses three images of different types of defects to generate heat maps, which intuitively show which features the model extracts for learning prediction. Figure 7 As shown in the figure, compared with other methods, the method proposed in the present invention can better cover the defect area in the sample image and pay more attention to the more prominent and easily observed positions (the darkest positions in the heat map). In other words, the method proposed in the present invention learns to use the information of the target object area, can pay attention to features with different characteristics and high discrimination, and extract features from them for classification and regression.
[0116] Example 1:
[0117] The present invention provides an embodiment to verify the proposed detection method. The example data comes from an aluminum alloy ingot casting workshop in Guizhou, China. The aluminum alloy ingots eliminated from the casting line are photographed and selected, and the types and characteristics of their surface defects are recorded. A data set is created through data enhancement, defect annotation and other methods. There are three types of defects recorded in total, namely slag inclusion, flash and burr, and the ratio of training set to test set is 9:1.
[0118] The experimental environment includes Ubuntu 22.04LTS Linux system, PyCharm 2022 development platform, PyTorch1.13.1 deep learning development architecture, Python 3.9 programming language, CPU is i9-12900KF, 32G memory, GPU is NVIDIARTX3090Ti graphics card, video memory is 24G, 500G SSD solid state drive, and CUDA version is 11.6.
[0119] In order to evaluate the effectiveness of the proposed model, the proposed method is compared with several popular methods. They are SSD, Faster-RCNN, EDDN, YOLOX, RetinaNet, YOLOv8s, and YOLOv5s. As can be seen from Table 2, compared with other methods, our proposed model has the highest mAP, the best accuracy in the slag inclusion and burr defect categories, and the highest FPS. The research results show that our detection model Al-YOLO has comprehensive surface defect detection capabilities for aluminum alloy ingots.
[0120] Table 2
[0121] method mAP Slag inclusion Fly Edge glitch FPS SSD 67.6 80.7 74.1 47.5 11.9 Faster-RCNN 69.2 81.3 78.6 46.9 17.6 EDDN 65.2 80.5 72.5 42.9 72.5 YOLOX 68.2 81.8 73.9 47.7 47.0 RetinaNet 65.8 79.4 74.3 43.7 56.2 YOLOv8s 67.5 81.1 74.2 47.0 62.3 YOLOv5s 68.5 83.7 74.8 45.8 45.9 Ours 72.5 84.5 76.0 51.2 57.1
[0122] The present invention solves the problem that there are few studies on surface defect detection of aluminum alloy ingots and there is no public dataset. The invention solves the problem that the original anchor frame of YOLOv5 is obtained by clustering during the training process of COCO dataset or VOC dataset, and is not applicable to the application scenario of aluminum alloy ingot. Combined with the structural reparameterization method, the time consumption of inference is reduced, which is more conducive to industrial deployment; a variety of attention mechanisms are combined to enhance the detection of small defects. Mixup, Mosaic and Mixup are used to randomly mix images and labels, enrich the training data and reduce the demand for video memory; the introduction of soft maximum suppression (Soft_NMS) solves the problem of sample imbalance caused by fewer burr samples.
[0123] Embodiment 2:
[0124] The embodiment of the present invention further provides a production line aluminum alloy ingot surface defect detection device, comprising:
[0125] An acquisition module is used to collect a data set of surface defect images of aluminum alloy ingots;
[0126] The first processing module is used to select YOLOv5 as the detection model and use the K-means++ algorithm to optimize the initial anchor frame according to the application scenario;
[0127] The second processing module is used to accelerate the reasoning of the YOLOv5 detection model and integrate the attention mechanism dynamic detection head Dyhead;
[0128] The training module is used to enhance the data set using the Mixup and Mosaic data enhancement algorithms and train the improved YOLOv5 detection model, and introduce the Focal loss function and non-maximum suppression during training;
[0129] The detection module is used to detect the surface defect images of aluminum alloy ingots using the trained model to obtain the type confidence and location information of the defects in the image.
[0130] As an implementation method of an embodiment of the present invention, a multi-branch structure is used to accelerate the reasoning of the YOLOv5 detection model, wherein the multi-branch structure includes six branches: BN fusion, branch merging, convolution sequence merging, depth stitching merging, mean pooling conversion and multi-scale convolution conversion.
[0131] As an implementation method of an embodiment of the present invention, DyHead combines three self-attention mechanisms into the detection head, redefines the four-dimensional tensor L×H×W×C as L×S×C to obtain a three-dimensional tensor, and uses scale-aware attention, space-aware attention, and task-aware attention in the three dimensions of scale L, space S, and channel C, respectively.
[0132] Embodiment 3:
[0133] An embodiment of the present invention also provides a production line aluminum alloy ingot surface defect detection system, comprising: a memory and a processor, wherein the memory stores a computer program run by the processor, and the computer program executes a production line aluminum alloy ingot surface defect detection method when run by the processor.
[0134] Embodiment 4:
[0135] An embodiment of the present invention further provides a storage medium, on which a computer program is stored, and when the computer program is run, a method for detecting surface defects of aluminum alloy ingots in a production line is executed.
[0136] The embodiments described above are only descriptions of the preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Without departing from the design spirit of the present invention, various modifications and improvements made to the technical solutions of the present invention by ordinary technicians in this field should all fall within the protection scope determined by the claims of the present invention.
Claims
1. A method for detecting surface defects of aluminum alloy ingots in a production line, characterized in that: include: Collecting aluminum alloy ingot surface defect image dataset; YOLOv5 is selected as the detection model, and the K-means++ algorithm is used to optimize the initial anchor box according to the application scenario; Improve the YOLOv5 detection model by accelerating reasoning and integrating the attention mechanism dynamic detection head Dyhead; The Mixup and Mosaic data enhancement algorithms are used to enhance the data set and train the improved YOLOv5 detection model. The Focal loss function and non-maximum suppression are introduced during training. The trained model is used to detect the surface defect images of aluminum alloy ingots to obtain the type confidence and location information of the defects in the images.
2. The method for detecting surface defects of aluminum alloy ingots in a production line according to claim 1, characterized in that: A multi-branch structure is used to accelerate the reasoning of the YOLOv5 detection model. The multi-branch structure includes six branches: BN fusion, branch merging, convolution sequence merging, depth stitching merging, mean pooling conversion and multi-scale convolution conversion.
3. The method for detecting surface defects of aluminum alloy ingots in a production line according to claim 2, characterized in that: DyHead combines the three self-attention mechanisms into the detection head, redefines the four-dimensional tensor L×H×W×C as L×S×C to obtain a three-dimensional tensor, and uses scale-aware attention, space-aware attention, and task-aware attention in the three dimensions of scale L, space S, and channel C respectively.
4. A production line aluminum alloy ingot surface defect detection device, characterized in that: include: An acquisition module is used to collect a data set of surface defect images of aluminum alloy ingots; The first processing module is used to select YOLOv5 as the detection model and use the K-means++ algorithm to optimize the initial anchor frame according to the application scenario; The second processing module is used to accelerate the reasoning of the YOLOv5 detection model and integrate the attention mechanism dynamic detection head Dyhead; The training module is used to enhance the data set using the Mixup and Mosaic data enhancement algorithms and train the improved YOLOv5 detection model, and introduce the Focal loss function and non-maximum suppression during training; The detection module is used to detect the surface defect images of aluminum alloy ingots using the trained model to obtain the type confidence and location information of the defects in the image.
5. The surface defect detection device for aluminum alloy ingots of a production line according to claim 4, characterized in that: A multi-branch structure is used to accelerate the reasoning of the YOLOv5 detection model. The multi-branch structure includes six branches: BN fusion, branch merging, convolution sequence merging, depth stitching merging, mean pooling conversion and multi-scale convolution conversion.
6. The surface defect detection device for aluminum alloy ingots of a production line according to claim 5, characterized in that: DyHead combines the three self-attention mechanisms into the detection head, redefines the four-dimensional tensor L×H×W×C as L×S×C to obtain a three-dimensional tensor, and uses scale-aware attention, space-aware attention, and task-aware attention in the three dimensions of scale L, space S, and channel C respectively.
7. A production line aluminum alloy ingot surface defect detection system, characterized in that: include: A memory and a processor, wherein the memory stores a computer program executed by the processor, and when the computer program is executed by the processor, the method for detecting surface defects of aluminum alloy ingots in a production line as described in any one of claims 1 to 3 is executed.
8. A storage medium, characterized in that: The storage medium stores a computer program, and the computer program, when running, executes the production line aluminum alloy ingot surface defect detection method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Lightweight target detection method and system based on structure re-parameterization
CN115861646A
PCB defect detection method based on improved YOLOv5 and storage medium
CN116245817A
PCB surface defect detection method based on improved YOLOv5 algorithm
CN116309427A
Wall-climbing robot metal working surface defect detection method based on improved YOLOv7
CN116758035A
Aluminum profile surface defect detection method with attention guiding function
CN117408953A
Cited By
Quality detection method, device and equipment based on metal ingot and storage medium
CN119887768A
Cage stranding defect detection method and system
CN120451745A
High-reflection and high-transmittance material surface flaw detection method based on improved YOLOv11
CN120580221A
Solar module junction box detection system, method and device, product and medium
CN120900954A
Sub-cartridge case surface defect detection method and image training and reasoning integrated platform
CN121304597A