Special-shaped copper strip defect real-time detection method and system, terminal equipment and storage medium
By introducing ASFF module, slim-neck module and inner-SIoU loss function in the special copper strip defect detection model, the problem of inefficient detection accuracy and efficiency of surface defect detection in the existing technology is solved, and higher detection accuracy is achieved and faster detection speed.
Patent Information
- Application Number
- CN202411608415.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-02-25
AI Technical Summary
The prior art has problems of detection accuracy and inefficiency in the detection of surface defects of special-shaped copper tapes, especially when facing defects of different types and small sizes of surfaces of special-shaped copper tapes, error detection and missed detection are prone to occur.
Adaptive spatial feature fusion (ASFF) module, slim-neck module and inner-SIoU loss function are introduced to build a special-shaped copper strip defect detection model based on the YOLOv8 network structure to improve the detection accuracy and efficiency of the model for special-shaped copper strip defects.
The ASFF module suppresses inconsistencies between different scale features, the slim-neck module reduces the model calculation amount, and the inner-SIoU loss function improves the detection accuracy of small objects, significantly improving the model's detection ability and efficiency of surface defects of the special-shaped copper belt.
Smart Images

Figure CN119515838A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of target detection, and in particular to a real-time detection method for defects in special-shaped copper strips. Background Art
[0002] As a key copper processing material, special-shaped copper strip plays an important role in many fields such as industry, construction and electronics. Due to the influence of various factors such as rolling equipment and processing technology, various surface defects may occur in the copper strip during the production process. These surface defects will not only reduce the mechanical properties and corrosion resistance of the copper strip, but also may affect the performance and overall yield of subsequent products. At present, the defect detection of special-shaped copper strip in industrial production mainly relies on manual visual inspection. Although this method has a certain guarantee in accuracy, it is less efficient and is mainly suitable for systems with smaller production scales. In large-scale production, it will seriously affect production efficiency. In addition, due to the high intensity of manual inspection, long-term work of this kind will cause health problems such as visual damage to the staff.
[0003] To solve the above problems, the existing technology proposes the YOLO detection algorithm, but the algorithm mainly uses multi-scale feature fusion and convolution layer for image processing. These processing methods make the model have poor detection performance for small targets and targets with large scale changes. At the same time, deployment on resource-constrained devices will also result in limited real-time detection efficiency. Therefore, when faced with different types and small-sized defects on the surface of special-shaped copper strips, false detection and missed detection are prone to occur. For this reason, we propose a real-time detection method, system, terminal device and storage medium for special-shaped copper strip defects. Summary of the invention
[0004] The purpose of the present invention is to provide a real-time detection method, system, terminal device and storage medium for special-shaped copper strip defects, introduce an ASFF detection head, a slim-neck module and an inner-SIoU module, and improve the detection accuracy and efficiency of special-shaped copper strip defects.
[0005] According to a first aspect of the present invention, in order to achieve the above-mentioned purpose, the present invention provides the following technical solution: a real-time detection method for defects in special-shaped copper strips, comprising:
[0006] Receive images of special-shaped copper strips, construct an image dataset, perform image preprocessing, and divide the preprocessed images into a training set, a validation set, and a test set;
[0007] A special-shaped copper strip defect detection model based on the YOLOv8 network structure is constructed. The special-shaped copper strip defect detection model adopts an adaptive spatial feature fusion module to replace the original Head structure, adopts a slim-neck module to replace the original Neck structure, and adopts an inner-SIoU loss function to replace the original CIoU loss function;
[0008] The training set is used to train the special-shaped copper strip defect detection model, and the verification set is input into the trained special-shaped copper strip defect detection model. The model is evaluated using the test results to obtain the trained special-shaped copper strip defect detection model.
[0009] The defect image of the special-shaped copper strip to be detected is input into the trained special-shaped copper strip defect detection model and the detection result is output.
[0010] Furthermore, the image of the special-shaped copper strip is acquired by collecting it with a camera.
[0011] Furthermore, the image preprocessing method is specifically as follows:
[0012] (1) The number of images is expanded by introducing Gaussian noise, random cropping, padding, and flipping methods;
[0013] (2) Use the labelimg tool to label the expanded special-shaped copper strip images in yolo format to obtain a dataset of defective images of special-shaped copper strips;
[0014] (3) The image dataset is divided into training set, validation set and test set in the ratio of 8:1:1.
[0015] Furthermore, the adaptive spatial feature fusion module comprises an equal scaling unit and an adaptive fusion unit:
[0016] (1) In the constant scaling unit, the feature map x n (n∈{1,2,3}, n represents the number of layers, n=1 represents the first layer) is adjusted to the same size as the feature map x1, and then the resolution and number of channels are ensured to be the same through interpolation and convolution layer processing methods;
[0017] (2) The adaptive fusion unit multiplies the feature maps of different scales by their corresponding weight maps pixel by pixel, and then performs weighted summation to generate the final fused feature map, specifically:
[0018] In the three-layer feature map (x1, x2, x3) output by FPN, the pixel-by-pixel weight scalar mapping (λlα, λlβ, λlγ) in each layer of the feature map is calculated using 1x1 convolution, and the corresponding weight parameters (α, β, γ) are calculated with the softmax function. Then, the feature information (X1, X2, X3) obtained from FPN is multiplied by the weight parameters and added to obtain new fusion features (ASFF-1, ASFF-2, ASFF-3). This fusion enables each pixel to obtain the optimal feature representation from each scale.
[0019] Among them, the calculation formula of α parameter is:
[0020]
[0021] ASFF-1:
[0022] ASFF-1=α 1 X1+β l ·X2+γ l ·X3.
[0023] Furthermore, the slim-neck module uses GSConv to replace the neck convolution part. GSConv includes standard convolution and depth-separable convolution, which is used to reduce the amount of model calculation while achieving the same effect as the original convolution.
[0024] The GS bottleneck and cross-stage partial network module are introduced after the GSConv. The GS bottleneck is composed of GSConv and is used to improve the expression ability of nonlinear information; the cross-stage partial network module adopts a one-time aggregation strategy design to replace the C2f part of the original neck structure, which is used to fuse information between different feature maps and reduce network complexity.
[0025] Furthermore, the inner-SIoU loss function adds a scale factor ratio on the basis of the SIoU loss function to calculate the scale of the auxiliary bounding box for controlling the loss, wherein the small-scale auxiliary border calculates the IoU to accelerate the regression of high IoU samples, and the large-scale auxiliary border calculates the IoU to accelerate the regression process of low IoU samples.
[0026] Furthermore, the Inner-SIoU loss function includes four loss functions: angle loss Angle cost, distance loss Distancecost, shape loss Shape cost and intersection loss IoU cost, among which:
[0027] (1) Angle loss:
[0028]
[0029] Where
[0030]
[0031] (2) Distance loss:
[0032]
[0033] (3) Shape loss:
[0034]
[0035] (4) Merger loss:
[0036]
[0037] Where w and h represent the width and height of the predicted bounding box, and w gt and h gt represents the width and height of the actual bounding box, α represents the angle between the center point of the predicted bounding box and the ground truth bounding box, which represents the offset between the predicted bounding box and the actual bounding box. The angle loss is used to maximize the convergence of α, c w and c h are two center points B and B GT The width and height of the rectangle, σ is the distance between the center points, which is used to calculate sinα to determine the center offset angle of the two types of boxes, and c W and c H Indicates the width and height of the minimum bounding rectangle containing the two boxes, and obtains the distance between the two types of boxes. and The width and height of the auxiliary bounding box for ratio are calculated to control the loss. When detecting small objects, ratio controls the reduction of the auxiliary box. θ is used as the degree of attention to control the shape loss. The parameter range of θ is set to [4,6].
[0038] (5) The inner-SIoU loss function calculation formula is:
[0039]
[0040] Where IoU represents the intersection-over-union loss, Δ represents the distance loss, and Ω represents the shape loss.
[0041] According to a second aspect of the present invention, the present invention provides a real-time detection system for defects in special-shaped copper strips, comprising:
[0042] The preprocessing module is used to receive the images of special-shaped copper strips, construct an image data set, and perform image preprocessing, and divide the preprocessed images into a training set, a verification set, and a test set;
[0043] A construction module is used to construct a special-shaped copper strip defect detection model based on the YOLOv8 network structure, wherein the special-shaped copper strip defect detection model adopts an adaptive spatial feature fusion module to replace the original Head structure, adopts a slim-neck module to replace the original Neck structure, and adopts an inner-SIoU loss function to replace the original CIoU loss function;
[0044] A training module is used to train the special-shaped copper strip defect detection model using the training set, input the verification set into the trained special-shaped copper strip defect detection model, evaluate the model using the test results and obtain the trained special-shaped copper strip defect detection model;
[0045] The output module is used to input the defect image of the special-shaped copper strip to be detected into the trained special-shaped copper strip defect detection model and output the detection result.
[0046] According to a third aspect of the present invention, the present invention provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the memory stores a computer program capable of running on the processor, and when the processor loads and executes the computer program, the above-mentioned real-time detection method for defects of special-shaped copper strips is adopted.
[0047] According to a fourth aspect of the present invention, the present invention provides a storage medium comprising computer executable instructions, wherein the computer executable instructions are used to execute the above-mentioned method for real-time detection of defects in special-shaped copper strips when executed by a computer processor.
[0048] The present invention has at least the following beneficial effects:
[0049] 1. In order to enhance the model's ability to accurately identify different defects of special-shaped copper strips, the present invention integrates an adaptive spatial feature fusion (ASFF) module in the detection head, which can suppress the inconsistency between features of different scales and effectively improve the model's ability to extract and identify defect features.
[0050] 2. In order to improve the detection rate of the model, the present invention adopts a slim-neck module to replace the original Neck structure, wherein the GSConv module can speed up the prediction calculation of the image, and the VoVGSCSP module can enhance feature fusion and reduce model parameters, thereby improving the feature extraction capability of the surface defects of special-shaped copper strips.
[0051] 3. In order to improve the model's ability to recognize small target defects, the present invention introduces the inner-SIoU loss function to replace the original loss function in YOLOv8. The inner-SIoU introduces a scaling factor to control the scale of the auxiliary border, which can better utilize the geometric features of the defects and shows obvious advantages in accelerating the model convergence speed and improving the small target detection accuracy.
[0052] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 It is a schematic diagram of the process of the method of the present invention;
[0054] Figure 2 It is a structural schematic diagram of the improved defect detection model of special-shaped copper strips of the present invention;
[0055] Figure 3Schematic diagram of the fusion principle of the adaptive spatial feature fusion module in the present invention;
[0056] Figure 4 It is a schematic diagram of the structure of the cross-stage partial network module in the present invention;
[0057] Figure 5 Schematic diagram of the principle of the Inner-SIoU loss function in the present invention;
[0058] Figure 6 Schematic diagram of image processing of different defects on the surface of special-shaped copper strips according to the present invention, wherein (a) is the acquisition image, (b) is the flip processing image, and (c) is the Gaussian noise processing image;
[0059] Figure 7 Schematic diagram of different defect types on the surface of the special-shaped copper strip of the present invention, wherein (A) is a forging mark defect, (B) is a pitting defect, (C) is a ripple defect, and (D) is a scratch defect;
[0060] Figure 8 A schematic diagram of the precision-recall rate curve and the training loss curve between the special-shaped copper strip defect detection model improved by the present invention and other different models;
[0061] Fig. 9 This is a heat map of the improved special-shaped copper strip defect detection model of the present invention and the initial YOLOv8n model for detecting different defect types. DETAILED DESCRIPTION
[0062] The following will be combined with the drawings in the embodiments of the present disclosure to clearly and completely describe the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0063] Embodiment 1:
[0064] See also Figure 1-Figure 9 The present invention provides a technical solution: a real-time detection method for defects in special-shaped copper strips, comprising:
[0065] S1. Receive images of special-shaped copper strips, construct an image dataset, and perform image preprocessing, and divide the preprocessed images into a training set, a validation set, and a test set;
[0066] For the technical solution of this embodiment, the quality of the data set has a significant impact on the design and training results of the target detection algorithm. The surface defect data set of special-shaped copper strips comes from a well-known copper processing company. The image data of the data set is collected in the production workshop using a camera, including 600 normal special-shaped copper strips and 800 defective special-shaped copper strips. In order to solve the problem of insufficient data sets, this embodiment preprocesses the images. The specific method is as follows:
[0067] (S11) The number of images is expanded by introducing Gaussian noise, random cropping, padding and flipping methods;
[0068] (S12) and using the labelimg tool to label the expanded special-shaped copper strip image in yolo format to obtain a special-shaped copper strip defect image dataset;
[0069] (S13) Dividing the image dataset into a training set, a validation set, and a test set in a ratio of 8:1:1,
[0070] The training set is used to train the model, the validation set is used to evaluate the network convergence effect and select appropriate hyperparameters to prevent overfitting, and the test set is used to evaluate the performance of the model on new data to ensure that the data set can be fully utilized in training. The data set contains a total of 4 types of defects, including forging marks, pits, ripples and scratches. In addition, the different types of defects on the surface of special-shaped copper strips are as follows Figure 7 As shown, the image processing of defects is as follows Figure 6 As shown;
[0071] S2. Construct a special-shaped copper strip defect detection model based on the YOLOv8 network structure, wherein the special-shaped copper strip defect detection model uses an adaptive spatial feature fusion module to replace the original Head structure, a slim-neck module to replace the original Neck structure, and an inner-SIoU loss function to replace the original CIoU loss function;
[0072] (S21) When the camera collects image information on the surface of the special-shaped copper strip, defect images of different sizes will be obtained. YOLOv8 mainly uses PAN-FPN to complete multi-scale feature extraction and fusion of defects. However, when fusing features at different levels, useless feature information is fused in due to the direct splicing method, which leads to feature degradation of the feature pyramid and reduces the effectiveness of the feature pyramid. Therefore, in order to solve the above problem, this embodiment introduces an adaptive spatial feature fusion module (ASFF), which aims to better obtain the feature information of the detection target by adaptively fusing feature maps at different levels. The principle of ASFF is as follows: Figure 3As shown in the figure, level1, level2, and level3 represent features at different levels in the feature pyramid, stride represents the stride of upsampling or downsampling, and ASFF-1, ASFF-2, and ASFF-3 represent adaptive feature fusion at different levels in ASFF.
[0073] In the feature extraction stage, the ASFF module first defines a neural network model with multiple convolutional layers and weight calculation layers to generate adaptive weights, then performs weighted fusion on feature maps of different levels to achieve adaptive fusion, and finally passes the fused features to the target detection head for target classification and positioning. Compared with the original direct splicing fusion method, it can better capture the multi-scale feature information of the target and filter out useless feature information, thereby alleviating the feature degradation problem of the feature pyramid, significantly improving the ability of the feature pyramid to utilize features of different scales, and enhancing the detection effect of targets of different scales. Since the surface defect detection of special-shaped copper strips contains a large number of target defects of different shapes and sizes, the introduction of ASFF can better obtain the feature information of defects of different sizes, thereby improving the detection ability of surface defects of special-shaped copper strips;
[0074] Specifically, the adaptive spatial feature fusion module includes an equal scaling unit and an adaptive fusion unit. In the equal scaling unit, the size, resolution and number of channels of feature maps at different levels are different, which will affect the effect of adaptive fusion. n (n∈{1,2,3}, n represents the number of layers, n=1 represents the first layer) is adjusted to the same size as the feature map x1, and then interpolation, convolutional layer processing and other methods are used to ensure the same resolution and number of channels;
[0075] The adaptive fusion unit multiplies the feature maps of different scales with their corresponding weight maps pixel by pixel, and then performs weighted summation to generate the final fused feature map. The effect is that in the three-layer feature map (x1, x2, x3) output by FPN, the 1x1 convolution is used to calculate the pixel-by-pixel weight scalar mapping (λlα, λlβ, λlγ) in each layer of the feature map, and the corresponding weight parameters (α, β, γ) are calculated with the softmax function. Finally, the feature information (X1, X2, X3) obtained from FPN is multiplied by the weight parameters and then added to obtain new fused features (ASFF-1, ASFF-2, ASFF-3). This fusion enables each pixel to obtain the optimal feature representation from each scale.
[0076] Among them, the calculation formula of α parameter is:
[0077]
[0078] ASFF-1:
[0079] ASFF-1=α 1 X1+β l ·X2+γ l X3;
[0080] (S22) The neck module of YOLOv8 mainly adopts the traditional convolution mode. In the traditional convolution, each convolution operation gradually transfers the spatial information of the image to the channel, and the spatial compression of the feature map and the expansion of the channel will cause partial loss of semantic information. Although dense convolution maximizes the retention of hidden connections between each channel, sparse convolution will completely cut off these connections, resulting in a decrease in the ability to extract features of the target. At the same time, the traditional convolution module has a large number of parameters, which makes the real-time performance of the model poor. The slim-neck module first proposed GSConv, which includes standard convolution and depthwise separable convolution, to replace the neck convolution part. GSConv can maintain a low time complexity and retain these connection channels as much as possible, thereby achieving the same effect as the original convolution while reducing the amount of model calculation. Then, after GSGonv, the GS bottleneck (GSbottleneck) and the cross-stage partial network module (VoV-GSCSP module) were introduced, such as Figure 4 As shown, the GS bottleneck is composed of GSConv, which can improve the expression ability of nonlinear information. VoV-GSCSP adopts a one-time aggregation strategy to replace the C2f part of the original neck, which is used to fuse information between different feature maps and reduce network complexity;
[0081] Specifically, the slim-neck module enhances the ability to extract feature information of different defects, reduces the number of model parameters while maintaining accuracy, and generally improves the model's detection speed and recognition ability for surface defects of special-shaped copper strips;
[0082] (S23) The CIoU loss function adopted by the original YOLOv8 structure can better adapt to the detection tasks of targets of various sizes and shapes. However, since the direction of mismatch between the required real box and the predicted box is not taken into account, the model training will have a slow convergence speed and poor detection and positioning ability when facing tiny defects, and the loss function is not generalizable when facing different types of defects. In order to solve this problem, this embodiment introduces the inner-SIoU loss function. On the basis of SIoU, inner-SIoU adds a scale factor ratio to calculate the scale of the auxiliary bounding box for controlling the loss. Among them, the calculation of IoU of the auxiliary bounding box with a smaller scale will help the regression of high IoU samples, and the calculation of IoU of the auxiliary bounding box with a larger scale will accelerate the regression process of low IoU samples, thereby solving the problem of poor generalization of the loss function when facing tiny defects and improving the detection accuracy of the model.
[0083] The Inner-SIoU loss function includes four loss functions: angle loss Angle cost, distance loss Distance cost, shape loss Shape cost and intersection loss IoU cost, among which:
[0084] (S231) Angle loss:
[0085]
[0086] Where
[0087]
[0088] change
[0089] (S232) Distance loss:
[0090]
[0091] (S233) Shape loss:
[0092]
[0093] (S234) Merge loss:
[0094]
[0095] Where w and h represent the width and height of the predicted bounding box, and w gt and h gt represents the width and height of the actual bounding box, α represents the angle between the center point of the predicted bounding box and the ground truth bounding box, which represents the offset between the predicted bounding box and the actual bounding box. Utilizing the angle loss to maximize the convergence of α is helpful for loss function regression. In addition, c w and c h are two center points B and B GT The width and height of the rectangle, σ is the distance between the center points, which is used to calculate sinα to determine the center offset angle of the two types of boxes, and c W and c H Indicates the width and height of the minimum bounding rectangle containing the two boxes, and obtains the distance between the two types of boxes. and The width and height of the auxiliary bounding box for controlling loss are calculated for ratio. When detecting small objects, reducing the auxiliary box can improve the detection effect of small objects. θ is used as the attention level for controlling shape loss. To prevent the attention level from being too high, which will limit the movement of the predicted bounding box and affect the detection effect, the parameter range of θ is set to [4,6].
[0096] (S235) The inner-SIoU loss function calculation formula is:
[0097]
[0098] Where IoU represents the intersection-over-union loss (the intersection-over-union ratio of the predicted bounding box and the actual bounding box), Δ represents the distance loss (the width, height and width, height ratio of the minimum bounding rectangle between the center point of the actual bounding box and the predicted bounding box are combined with the angle loss to achieve the distance and angle association between the two bounding boxes and ensure the balance of the distance and angle between the two), and Ω represents the shape loss (the shape difference between the actual bounding box and the predicted bounding box is judged from the length and width);
[0099] S3. Use the training set to train the special-shaped copper strip defect detection model, and input the verification set into the trained special-shaped copper strip defect detection model, and use the test results to evaluate the model and obtain the trained special-shaped copper strip defect detection model;
[0100] S4. Input the defect image of the special-shaped copper strip to be detected into the trained special-shaped copper strip defect detection model and output the detection result.
[0101] Next, the present invention will be further described in conjunction with specific embodiments:
[0102] 1. In order to improve the detection performance of surface defects of special-shaped copper strips, this embodiment proposes an improved model based on YOLOv8: YOLOv8-cop (special-shaped copper strip defect detection model). The advantages of this model are as follows: (1) The ASFF network is used to optimize the detection head, which can suppress the inconsistency between features of different scales to enhance the detection capability of defects of different sizes; (2) The slim-neck module is used to optimize the neck structure in the convolutional neural network, in which the GSConv module can speed up the prediction calculation of the image, and the VoVGSCSP module can enhance feature fusion and reduce model parameters, thereby improving the feature extraction capability of surface defects of special-shaped copper strips; (3) The inner-SIoU is used as the bounding box loss function, and the scale factor is introduced to control the scale of the auxiliary border, thereby improving the generalization ability of the model, accelerating the convergence speed of the model, and significantly improving the detection accuracy of the model for small target defects.
[0103] The experiment in this embodiment was run on a Windows 11 system equipped with an Intel i5-13400F CPU, NVIDIA RTX 4090, and CUDA 11.3. The software environment configuration included Python 3.8.1 and PyTorch 11.7.
[0104] 2. Experimental Dataset
[0105] With respect to the technical solution of this embodiment, the quality of the data set has a significant impact on the design and training results of the target detection algorithm. The surface defect data set of special-shaped copper strips comes from a well-known copper processing enterprise. The image data of the data set is collected by a camera in the production workshop, including 600 normal special-shaped copper strips and 800 defective special-shaped copper strips. To solve the problem of insufficient data set quantity, this embodiment adopts data enhancement technology to expand the data set to 2000 by introducing Gaussian noise, random cropping, padding and flipping, and then randomly divides the data set into training set, validation set and test set. The training set is used to train the model, the validation set is used to evaluate the network convergence effect and select appropriate hyperparameters to prevent overfitting, and the test set is used to evaluate the performance of the model on new data. The ratio of the three is 8:1:1 to ensure that the data set can be fully utilized in training. The data set contains a total of 4 defects, including forging marks, pitting, ripples and scratches. In addition, the different defect types on the surface of the special-shaped copper strips are as follows Figure 7 As shown, the image processing of defects is as follows Figure 6 shown.
[0106] 3. Evaluation Criteria
[0107] In order to evaluate the performance of the YOLOv8-cop model, this embodiment uses precision (P), recall (R) and mean average precision (mAP) as the evaluation criteria for detection performance;
[0108] Precision evaluates how many samples predicted as positive are correctly predicted, and recall evaluates how many samples that are actually positive are predicted as positive. By calculating the values of true positive (TP), false positive (FP), and false negative (FN), the precision and recall of the model can be calculated;
[0109] The formulas for precision P and recall R are as follows:
[0110]
[0111] Average Precision (AP) represents the area under the PR curve, while Mean Average Precision (mAP) evaluates the accuracy at different recall levels and then calculates the average accuracy of these levels. mAP represents the comprehensive performance of the evaluation model in all categories; the higher the mAP, the better the performance of the object detection task. The formulas for AP and mAP are as follows:
[0112]
[0113] In this study, there are four types of defects in the special-shaped copper strip, so K = 4;
[0114] 4. Comparison and analysis of different improvement results
[0115] 41. Comparison of different detection heads
[0116] In order to verify the impact of different detection heads on target detection performance, the study adopted five different improvement schemes for the detection head of YOLOv8: AFPN
[46] , ASFF, RepHead
[47] , FASFFHead
[33] and FRMHead. Therefore, six models were designed in the experiment, including YOLOv8n, YOLOv8n+AFPN, YOLOv8n+ASFF, YOLOv8n+RepHead, YOLOv8n+FASFFHead and YOLOv8n+FRMHead. These models were tested and compared on the surface defect dataset of special-shaped copper strips. The experimental results are shown in Table 1:
[0117] Table 1 Comparison of different detection head modules in the experiment
[0118]
[0119] Experimental results show that with the introduction of five detection heads, the detection effect of YOLOv8n+ASFF is greatly improved. Compared with the YOLOv8n algorithm, the accuracy is improved by 6.9 percentage points, the recall rate is improved by 1.4 percentage points, and the mAP@0.5 is improved by 2.2 percentage points. However, since YOLOv8n+ASFF needs to generate adaptive weights during the training process, its efficiency is slightly reduced. Compared with the improvement effects of other detection heads, the ASFF module is generally better than other detection heads in improving the ability to detect defects. Based on the above judgment, ASFF is the most suitable detection head improvement for the model.
[0120] 42. Comparison of different neck frames
[0121] In order to verify the influence of different neck improvements on the model parameters and detection capability, this embodiment proposes five different neck improvement schemes: slim-neck, BiFPN, HS-FPN, CCFM and GFPN[, and tests and compares these models on the surface defect data set of special-shaped copper strips. The experimental results are shown in Table 2:
[0122] Table 2 Comparison of different neck modules in the experiment
[0123]
[0124] The experimental results show that compared with the YOLOv8n model, slim-neck, BIFPN, CCFM, and GFPN have all improved in accuracy, and YOLOv8n+slim-neck, YOLOv8n+BiFPN, YOLOv8n+HS-FPN, and YOLOv8n+CCFM have all reduced the parameters of the model, making the improved model lightweight; although Slim-neck is not the most prominent in reducing the model parameters, other neck improvements will affect the model's defect detection ability, while slim-neck enhances the model's detection ability while ensuring the reduction of model parameters. Based on the above judgments, slim-neck is the most suitable lightweight improvement of the model.
[0125] 43. Comparison of different loss functions
[0126] This embodiment adds different loss functions to the YOLOv8n+ASFF+slim-neck model for experimental comparison. This embodiment selects six loss functions, namely CIoU, SIoU, GIoU, EIoU, MPDIoU and inner-SIoU, and uses evaluation indicators for analysis. The experimental results are shown in Table 3. The experimental results show that inner-SIoU is generally better than other loss functions. The experiment shows that inner-SIoU can better adapt to the geometric characteristics of metal surface defects and further improve the model's ability to identify defects.
[0127] Table 3 Comparison of different loss experiments in the experiment
[0128]
[0129] 5. Ablation Experiment
[0130] In order to further study the impact of the three improved modules on the performance of the YOLOv8n model, this embodiment uses different combinations of the three improved modules in each of the eight experiments while ensuring the same parameters, environment configuration and data set. The evaluation index is used and the FPS is compared for analysis. The experimental results are shown in Table 4:
[0131] Table 4 Ablation experiment
[0132]
[0133] Experimental data show that each improved combination has a certain improvement in accuracy. After adding the ASFF model, the accuracy increased by 6.9 percentage points and the mAP increased by 2.2 percentage points, indicating that the detection head optimized by ASFF can better utilize the multi-scale target detection and significantly improve the performance of defect detection. The Slim-neck module replaced the neck module of the original model, which increased the mAP by 4.2 percentage points and the FPS by 9fps. This improvement not only improved the model detection speed, but also ensured the improvement of the model detection accuracy. The inner-SIoU was used to replace the original CIoU loss function, and the accuracy was improved by 8.4 percentage points. In summary, the three improvements have improved the model in different aspects. In terms of results, YOLOv8-cop has improved the accuracy by 8 percentage points, the mAP value by 3.8 percentage points, and the FPS by 9fps compared with the original model. The experiment fully verified the effectiveness of the improvement scheme.
[0134] 6. Comparative Experiment
[0135] 61. Comparison of the effects of different algorithms
[0136] In order to evaluate the performance of the YOLOv8-cop model, this embodiment sets up a comparative experiment of the effects of different algorithms, and compares the Faster R-CNN, SSD, YOLOv3, YOLOv5, YOLOv7, YOLOv8 and YOLOv10 models with the YOLOv8-cop model. The experimental results are shown in Table 5:
[0137] Table 5 Comparative experiments of eight different models
[0138]
[0139]
[0140] Experimental data show that compared with other models, YOLOv8-cop maintains advantages in all evaluation indicators throughout the training results. Compared with Faster R-CNN, SSD, YOLOv3, YOLOv5, YOLOv7, YOLOv8 and YOLOv10 models, the accuracy of YOLOv8-cop model is improved by 46.7%, 34.8%, 6.5%, 30.8%, 26.3%, 8% and 13.5% respectively; mAP is improved by 3.8%, 4.9%, 2.3%, 1.5%, 1.6%, 2.9%, 3.9%, 4.9%, 5.9%, 6.5%, 3.6 ...6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6.5%, 6
[0141] 5.5%, 9.1%, 2.2%, 4.8%, 3.8%, and 2.8%. These experimental results demonstrate the effectiveness of the improvement in improving the model detection performance.
[0142] like Figure 8As shown, this embodiment makes a detailed comparative analysis of the precision-recall curve and the training loss curve between the YOLOv8-cop model and the YOLOv8n model. By analyzing the dynamic changes of the precision-recall curve, it can be seen that the curves of the two models gradually remain in a stable range as the number of training cycles increases. By analyzing the dynamic changes of the loss curve, it can be seen that the loss curves of the two models gradually transition to a stable state as the number of training cycles increases. These phenomena indicate that the model continuously extracts information from the training data and adjusts its internal parameters to adapt to and adapt to the data more accurately.
[0143] As for the precision-recall curve, in the first 15 training cycles, the precision and recall of the two models increased significantly. Although the introduction of the ASFF module and the slim-neck module caused large fluctuations in the initial training, the volatility of the precision and recall curves of the improved model decreased after 30 training cycles, and the precision and recall began to gradually exceed the YOLOv8n model. In the later stage of training, both curves basically gradually increased from maintaining to stabilizing, and the precision and recall of the YOLO8-cop model were generally higher than those of the YOLOv8n model, proving that ASFF and slim-neck can improve the model's ability to detect defects in special-shaped copper strips;
[0144] For the training loss curve, within the first 15 training cycles of training, the losses of both models showed a significant downward trend, which indicates that the models began to learn at a faster rate in the early stages. However, in the initial stage of training, the loss of the YOLOv8-cop model was slightly higher than that of the YOLOv8n model. This is mainly because the YOLOv8-cop model adds the ASFF module and the slim-neck module to the model. The addition of these new modules may temporarily increase the loss. Although this is the case in the early stages, after about 30 training cycles, the YOLOv8-cop model begins to show a faster decline in loss relative to the YOLOv8n model. In the later stages of the training process, the loss values of both models show a trend of gradual convergence, and the loss value of the YOLOv8-cop model is always lower than that of the YOLOv8n model. This phenomenon shows that the YOLOv8-cop model not only converges faster, but also has a better convergence effect, which further confirms the significant effect of the inner-SIoU loss function on improving model performance.
[0145] 62Comparison of different defect detection effects
[0146] This example explores the detection effect of the improved YOLOv8-cop model on different defect types on the surface of special-shaped copper strips, and compares the detection effects of Faster R-CNN, SSD, YOLOv3, YOLOv5, YOLOv7, YOLOv8 and YOLOv10 on different defect types. The experimental results are shown in Table 6:
[0147] Table 6 Comparative experiments on different defect detection
[0148]
[0149] Experiments show that the accuracy of forging marks of the YOLOv8-cop model is 98.5% and the mAP is 99.5%. The accuracy of pits is 95.8% and the mAP is 99.5%. The accuracy of ripples is 99.9% and the mAP is 99.5%. The accuracy of scratches is 95.7% and the mAP is 95.6%. Among them, although SSD is better in detecting large-scale defects, it is not effective in detecting small targets. The detection capabilities of the YOLO series algorithms are more balanced, but there is still room for improvement in detecting scratch defects.
[0150] In general, YOLOv8-cop has improved accuracy, recall rate and mAP compared with other algorithms. Experimental data show that compared with Faster R-CNN, SSD, YOLOv3n, YOLOv5n, YOLOv7-tiny, YOLOv8n and YOLOv10n, YOLOv8-cop is more suitable for the detection of different defects in special-shaped copper strips and meets the needs of defect detection.
[0151] 7. Visual comparison of model improvements
[0152] In order to intuitively demonstrate the detection optimization effect of the proposed YOLOv8-cop model on the surface defect dataset of special-shaped copper strips, this embodiment adopts the Grad-CAM (gradient weighted class activation mapping) algorithm for visualization analysis. This embodiment compares the heat maps of the initial YOLOv8n model and the improved YOLOv8-cop model for different defect types. The experimental results are shown in Figure 2. Fig. 9 As shown, the brighter the area, the higher the model's attention to that area. (The color represents a scalar of an order of magnitude, with hot tones (such as red or yellow) representing high-activity areas and cold tones (such as blue or green) representing low-activity areas.)
[0153] According to the comparison of these two types of heat maps, the improved model is better than the YOLOv8n model in terms of the area and attention level of high activity areas of the four types of defects, namely forging marks, pits, ripples and scratches. It can be concluded that compared with the YOLOv8n model, in the detection of surface defects of special-shaped copper plates and strips, the YOLOv8-cop model can enhance the focus on areas containing different defects and effectively improve the ability to detect surface defects of special-shaped copper plates and strips.
[0154] In general, in order to achieve high-precision real-time detection of surface defects of special-shaped copper strips, this embodiment proposes an improved YOLOv8-cop model based on the YOLOv8n framework to achieve surface defect detection of special-shaped copper strips. Considering that the scale of the existing data set is relatively small, this embodiment uses a data enhancement method to expand the number of data sets and improve the robustness of the model. At the same time, the model combines ASFF, slim-neck module and inner-SIoU loss function, in which the addition of ASFF enhances the model feature fusion effect and improves the accuracy of defect detection. The introduction of slim-neck module improvement reduces the model parameters while keeping the model detection capability unchanged and enhancing the model detection efficiency. The loss function inner-SIoU better utilizes the geometric properties of surface defects of special-shaped copper strips and improves the convergence speed and accuracy of the algorithm. In the comparative experiment, the improved model is compared with the current representative algorithm and has better detection effect.
[0155] In summary, the YOLOv8-cop model has achieved significant performance improvement in the task of surface defect detection of special-shaped copper strips. It not only has high detection accuracy, but also shows superiority in model detection speed, meeting the requirements of real-time detection. This will better apply the target detection algorithm to actual special-shaped copper strip defect detection projects, improve the accuracy and effectiveness of special-shaped copper strip defect detection, and thus provide strong support for the sustainable development of the copper processing industry.
[0156] Embodiment 2:
[0157] This embodiment provides a real-time detection system for defects in special-shaped copper strips, including:
[0158] The preprocessing module is used to receive the images of special-shaped copper strips, construct an image data set, and perform image preprocessing, and divide the preprocessed images into a training set, a verification set, and a test set;
[0159] A construction module is used to construct a special-shaped copper strip defect detection model based on the YOLOv8 network structure, wherein the special-shaped copper strip defect detection model adopts an adaptive spatial feature fusion module to replace the original Head structure, adopts a slim-neck module to replace the original Neck structure, and adopts an inner-SIoU loss function to replace the original CIoU loss function;
[0160] A training module is used to train the special-shaped copper strip defect detection model using the training set, input the verification set into the trained special-shaped copper strip defect detection model, evaluate the model using the test results and obtain the trained special-shaped copper strip defect detection model;
[0161] The output module is used to input the defect image of the special-shaped copper strip to be detected into the trained special-shaped copper strip defect detection model and output the detection result.
[0162] Specifically, the above-mentioned preprocessing module, construction module, training module and output module can be embedded in a computer processing system. The computer calls the above-mentioned modules to complete the task of detecting defects in special-shaped copper strips based on the above-mentioned real-time detection method for defects in special-shaped copper strips; the above-mentioned preprocessing module, construction module, training module and output module can perform operations according to the specific steps given in the real-time detection method for defects in special-shaped copper strips.
[0163] It should be noted that it should be understood that the division of the various modules of the above system is only the division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated, and these modules can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software calling through processing elements, and some modules can be implemented in the form of hardware. For example, the preprocessing module can be a separately established processing element, or it can be integrated in a certain chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a certain processing element of the above device. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by the hardware integrated logic circuit in the processor element or the instructions in the form of software.
[0164] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital singnal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0165] Embodiment three:
[0166] The present invention provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the memory stores a computer program capable of running on the processor, and when the processor loads and executes the computer program, the above-mentioned real-time detection method for defects of special-shaped copper strips is adopted.
[0167] It should be noted that the terminal device can be a computer device such as a desktop computer, a laptop computer or a cloud server, and the terminal device includes but is not limited to a processor and a memory. For example, the terminal device can also include input and output devices, network access devices and buses.
[0168] Furthermore, the processor may adopt a central processing unit (CPU). Of course, according to actual usage, other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. may also be adopted. The general-purpose processor may adopt a microprocessor or any conventional processor, etc., and the present application does not impose any restrictions on this.
[0169] Embodiment 4:
[0170] The present invention provides a storage medium containing computer executable instructions, characterized in that the computer executable instructions are used to execute the above-mentioned real-time detection method for defects of special-shaped copper strips when executed by a computer processor.
[0171] Among them, the computer program can be stored in a computer-readable medium, the computer program includes computer program code, the computer program code can be in the form of source code, object code, executable file or certain middleware, etc. The computer-readable medium includes any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the computer-readable medium includes but is not limited to the above-mentioned components.
[0172] It should be noted that, in this article, relational terms such as first and second, etc. 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 these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0173] For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to the specific circumstances. When an element is referred to as being "assembled on", "installed on", "fixed on" or "set on" another element, it can be directly on the other element or there can also be a centered element. When an element is considered to be "connected" to another element, it can be directly connected to the other element or there may be a centered element at the same time. The terms "vertical", "horizontal", "up", "down", "left", "right" and similar expressions used herein are only for illustrative purposes and are not intended to be the only implementation method.
[0174] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
[0175] In the description of this specification, the description with reference to the terms "one embodiment", "example", "specific example", etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
Claims
1. A real-time detection method for defects in special-shaped copper strips, characterized in that: include: Receive images of special-shaped copper strips, construct an image dataset, perform image preprocessing, and divide the preprocessed images into a training set, a validation set, and a test set; A special-shaped copper strip defect detection model based on the YOLOv8 network structure is constructed. The special-shaped copper strip defect detection model adopts an adaptive spatial feature fusion module to replace the original Head structure, adopts a slim-neck module to replace the original Neck structure, and adopts an inner-SIoU loss function to replace the original CIoU loss function; The training set is used to train the special-shaped copper strip defect detection model, and the verification set is input into the trained special-shaped copper strip defect detection model. The model is evaluated using the test results to obtain the trained special-shaped copper strip defect detection model. The defect image of the special-shaped copper strip to be detected is input into the trained special-shaped copper strip defect detection model and the detection result is output.
2. The real-time detection method for defects in special-shaped copper strips according to claim 1 is characterized in that: The image of the special-shaped copper strip is obtained by collecting it with a camera.
3. The real-time detection method for defects in special-shaped copper strips according to claim 2 is characterized in that: The image preprocessing method is specifically as follows: (1) The number of images is expanded by introducing Gaussian noise, random cropping, padding, and flipping methods; (2) Use the labelimg tool to label the expanded special-shaped copper strip images in yolo format to obtain a dataset of defective images of special-shaped copper strips; (3) The image dataset is divided into training set, validation set and test set in the ratio of 8:1:
1.
4. The real-time detection method for defects in special-shaped copper strips according to claim 2 is characterized in that: The adaptive spatial feature fusion module includes an equal scaling unit and an adaptive fusion unit: (1) In the constant scaling unit, the feature map x n (n∈{1,2,3}, n represents the number of layers, n=1 represents the first layer) is adjusted to the same size as the feature map x1, and then the resolution and number of channels are ensured to be the same through interpolation and convolution layer processing methods; (2) The adaptive fusion unit multiplies the feature maps of different scales by their corresponding weight maps pixel by pixel, and then performs weighted summation to generate the final fused feature map, specifically: In the three-layer feature map (x1, x2, x3) output by FPN, the pixel-by-pixel weight scalar mapping (λlα, λlβ, λlγ) in each layer of the feature map is calculated using 1x1 convolution, and the corresponding weight parameters (α, β, γ) are calculated with the softmax function. Then, the feature information (X1, X2, X3) obtained from FPN is multiplied by the weight parameters and added to obtain new fusion features (ASFF-1, ASFF-2, ASFF-3). This fusion enables each pixel to obtain the optimal feature representation from each scale. Among them, the calculation formula of α parameter is: ASFF-1: ASFF-1=a 1 ·X1+β l ·X2+γ l ·X3 5. The real-time detection method for defects in special-shaped copper strips according to claim 4 is characterized in that: The slim-neck module uses GSConv to replace the neck convolution part. GSConv includes standard convolution and depth-separable convolution, which is used to reduce the amount of model calculation while achieving the same effect as the original convolution. The GS bottleneck and cross-stage partial network module are introduced after the GSConv. The GS bottleneck is composed of GSConv and is used to improve the expression ability of nonlinear information; the cross-stage partial network module adopts a one-time aggregation strategy design to replace the C2f part of the original neck structure, which is used to fuse information between different feature maps and reduce network complexity.
6. The real-time detection method for defects in special-shaped copper strips according to claim 5 is characterized in that: The inner-SIoU loss function adds a scale factor ratio on the basis of the SIoU loss function to calculate the scale of the auxiliary bounding box for controlling the loss, wherein the small-scale auxiliary border calculates the IoU to accelerate the regression of high IoU samples, and the large-scale auxiliary border calculates the IoU to accelerate the regression process of low IoU samples.
7. The real-time detection method for defects in special-shaped copper strips according to claim 6 is characterized in that: The Inner-SIoU loss function includes four loss functions: angle loss Angle cost, distance loss Distance cost, shape loss Shape cost and intersection loss IoU cost, where: (1) Angle loss: Where (2) Distance loss: (3) Shape loss: (4) Merger loss: Where w and h represent the width and height of the predicted bounding box, and w gt and h gt represents the width and height of the actual bounding box, α represents the angle between the center point of the predicted bounding box and the ground truth bounding box, which represents the offset between the predicted bounding box and the actual bounding box. The angle loss is used to maximize the convergence of α, c w and c h are two center points B and B GT The width and height of the rectangle, σ is the distance between the center points, which is used to calculate sinα to determine the center offset angle of the two types of boxes, and c W and c H Indicates the width and height of the minimum bounding rectangle containing the two boxes, and obtains the distance between the two types of boxes. and The width and height of the auxiliary bounding box for ratio are calculated to control the loss. When detecting small objects, ratio controls the reduction of the auxiliary box. θ is used as the degree of attention to control the shape loss. The parameter range of θ is set to [4,6]. (5) The inner-SIoU loss function calculation formula is: Where IoU represents the intersection-over-union loss, Δ represents the distance loss, and Ω represents the shape loss.
8. Real-time detection system for defects in special-shaped copper strips, characterized in that: include: The preprocessing module is used to receive the images of special-shaped copper strips, construct an image data set, and perform image preprocessing, and divide the preprocessed images into a training set, a verification set, and a test set; A construction module is used to construct a special-shaped copper strip defect detection model based on the YOLOv8 network structure, wherein the special-shaped copper strip defect detection model adopts an adaptive spatial feature fusion module to replace the original Head structure, adopts a slim-neck module to replace the original Neck structure, and adopts an inner-SIoU loss function to replace the original CIoU loss function; A training module is used to train the special-shaped copper strip defect detection model using the training set, input the verification set into the trained special-shaped copper strip defect detection model, evaluate the model using the test results and obtain the trained special-shaped copper strip defect detection model; The output module is used to input the defect image of the special-shaped copper strip to be detected into the trained special-shaped copper strip defect detection model and output the detection result.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that: The memory stores a computer program that can be run on the processor. When the processor loads and executes the computer program, the real-time detection method for defects of special-shaped copper strips according to any one of claims 1 to 7 is adopted.
10. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the real-time defect detection method for special-shaped copper strips according to any one of claims 1 to 7 when executed by a computer processor.
Citation Information
Patent Citations
PCB surface defect detection method based on improved YOLOv5 algorithm
CN114372949A
YOLOX-based steel surface defect detection method, system, equipment and medium
CN117392052A
Power transmission line stockbridge damper image defect detection method based on YOLOv8s
CN118298159A
Substation equipment defect detection method and system based on improved YOLOv9
CN118469986A
Target detection method and device, equipment and storage medium
CN118864822A
Cited By
WSSRNet-based SAR image ship small target detection method
CN119942092A
Small target detection method of ship in SAR image based on WSSRNet
CN119942092B