Industrial product multi-type surface defect detection method based on improved YOLOv5 model
By improving the YOLOv5 model, high-quality defect images are generated and coordinated attention mechanism is introduced, combined with transfer learning and multi-level feature detection, the scarcity of samples and insufficient transfer capabilities in multi-type surface defect detection are solved, and high-precision and rapid adaptation detection effect is achieved.
Patent Information
- Application Number
- CN202510589942.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-08
- Publication Date
- 2025-08-05
AI Technical Summary
The existing defect detection methods are scarce in multiple types of surface defect samples, unbalanced defect recognition speed and accuracy, and insufficient model migration capabilities, resulting in poor detection accuracy and adaptability.
By improving the YOLOv5 model, the generation of high-quality defect images are introduced into the generative adversarial network, the coordination attention mechanism and the decoupling head detector are added, and the Progressive Subnetwork Fusion Transfer Model is used for transfer learning, combining multi-level feature detection and adaptive convolution kernel for detection.
Significantly expand the training data set, improve detection accuracy and speed, enhance the model's adaptability in different scenarios and products, and ensure efficient real-time detection.
Smart Images

Figure CN120431069A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision and deep learning technologies, and specifically to a method for detecting multiple types of surface defects of industrial products based on an improved YOLOv5 model. Background Art
[0002] With the advancement of industrial automation, surface defect detection plays an increasingly important role in product quality control. Traditional manual inspection methods, due to their low efficiency, high errors, and inability to meet the demands of large-scale production, are gradually being replaced by automated defect detection technologies based on computer vision and deep learning. However, existing defect detection methods still face numerous challenges, primarily the scarcity of samples of various surface defects, the balance between defect recognition speed and accuracy, and insufficient model transfer and application capabilities.
[0003] Currently, the scarcity of samples of various surface defects hinders the accuracy of deep learning models. Due to the wide variety and uneven distribution of defects, it is difficult to obtain sufficient, high-quality annotated data, resulting in deep learning models being unable to effectively learn the characteristics of various defects. Existing surface defect detection methods lack good transferability, making them difficult to adapt to different production environments and product variations, increasing costs and time. Summary of the Invention
[0004] In response to the shortcomings of the existing technology, the present invention provides a method for detecting multiple types of surface defects of industrial products based on an improved YOLOv5 model. The technical problem to be solved by this invention is: how to effectively learn the characteristics of various defects and increase the accuracy of detection through migration capabilities.
[0005] To achieve the above objectives, the present invention is implemented through the following technical solutions: a method for detecting multiple types of surface defects of industrial products based on an improved YOLOv5 model, comprising:
[0006] S1. Construct a surface defect dataset, generate defect images using a deep learning generative adversarial network, and expand the dataset using an improved deep convolutional generative adversarial network. By introducing a self-attention mechanism in the generator, the structure and detail accuracy of the generated images are improved. A channel-wise attention mechanism is introduced in the discriminator to enhance the ability to distinguish between real and generated images, thereby generating diverse and high-quality defect images.
[0007] S2. Improve the YOLOv5 model by adding a coordinated attention mechanism to the backbone network to address the position information loss caused by global pooling and enhance feature extraction capabilities. Decoupled head detectors are used to separate classification and regression tasks, thereby improving the model's detection accuracy and convergence speed.
[0008] S3. Introducing an improved transfer learning algorithm and proposing the Progressive Subnetwork Fusion Transfer Model, this model can be quickly transferred across different scenarios and products, improving the model's generalization capabilities and reducing the additional cost and workload associated with model conversion.
[0009] S4. Use the improved YOLOv5 model to detect surface defects and migrate its application to different production environments to ensure the high accuracy and speed of the model in real-time detection and adaptability to different defect types and production scenarios.
[0010] Preferably, S1 specifically includes:
[0011] S1.1 uses a generative adversarial network to generate surface defect images, wherein the generative adversarial network consists of a generator and a discriminator, and the output G(z) of the generator is processed by a self-attention mechanism A gen To enhance the utilization of global information, the output D(x) of the discriminator is obtained through the channel attention mechanism A dis Strengthen the dependencies between image channels to improve the quality of generated images:
[0012] G(z)=Gen(z,A gen )
[0013] D(x)=Dis(x,A dis )
[0014] S1.2 Label the generated defect images and ensure that the number of samples of each defect type in the dataset is balanced;
[0015] S1.3 uses the generated high-quality defect images and real images to expand the dataset and provide sufficient training samples to support the subsequent training of deep learning models.
[0016] Preferably, S2 specifically includes:
[0017] S2.1 Adding a coordinated attention mechanism to the backbone network of YOLOv5 coord , by taking the position information P loc It is embedded into channel attention to enhance feature extraction capability and is implemented by the following formula:
[0018] A coord (P loc )=σ(W coord ·P loc )
[0019] Among them, W coordis the weight matrix, σ is the Sigmoid activation function, and Ploc is the input position information, which represents the spatial position of the target area. By coordinating the attention mechanism, the important information of the target area can be effectively retained, while suppressing background noise and improving the feature extraction ability of the network;
[0020] S2.2 Using the decoupled head detector H in the head component of YOLOv5 de , respectively handling classification tasks and regression tasks:
[0021] H de =Cl(x)+Re(x)
[0022] The decoupled head detector described in step S2.2 includes independent classification branches and regression branches. The classification branch consists of two layers of 3×3 convolutions and one layer of 1×1 convolutions, and the regression branch consists of one layer of 3×3 convolutions followed by residual connections and one layer of 1×1 convolutions to optimize category prediction and bounding box regression, respectively.
[0023] S2.3 uses multi-scale feature fusion technology and combines high-resolution images for detection on a feature pyramid structure. The formula is as follows:
[0024]
[0025] Among them, F i is the feature map of layer i, α i is the scaling factor, the scaling factor α described in step S2.3 i is a learnable parameter, which is normalized to:
[0026]
[0027] Among them, w i is the original learnable value of the weight of the feature map of the i-th layer. When the feature map is upsampled by 2× after the multi-scale feature fusion, bilinear interpolation is used to maintain spatial continuity.
[0028] Preferably, S3 specifically includes:
[0029] S3.1 uses Progressive Subnetwork Fusion TransferModel in the transfer learning process, and gradually optimizes the subnetwork S i Learning strategies to improve the model's adaptability in different scenarios and products, specifically:
[0030]
[0031] Among them, λ i is the weight coefficient, S i is the i-th sub-network;
[0032] S3.2 performs data augmentation on the migration model and dynamically optimizes feature representation through feature mapping adjustments:
[0033]
[0034] in, It is a data enhancement operation.
[0035] Preferably, the PSF-TM adopts a gradual fusion strategy to fuse different sub-networks, where the sub-network is a small network for a specific scenario or task, to enhance the generalization ability of the model and adapt to new scenarios and tasks more quickly and effectively.
[0036] Preferably, the stepwise fusion strategy described in PSF-TM allows the model to share knowledge across multiple tasks while being fine-tuned for a specific task.
[0037] Preferably, S4 specifically includes:
[0038] S4.1 builds a multi-level feature detection module, extracts defect features of different scales in each layer of feature maps, and fuses them using the following formula:
[0039]
[0040] Among them, F i is the feature map of layer i, α i is the fusion weight coefficient of each layer, and m is the number of feature layers.
[0041] S4.2 uses a detection algorithm based on an adaptive convolution kernel to accurately locate defects of different scales and dynamically weight them based on different areas of the image:
[0042]
[0043] Among them, ω i is the weight of each feature map, Conv i is the convolution operation, F fused is the fused feature map, is the final detection output.
[0044] S4.3 uses global average pooling to post-process the detection results to eliminate excessive redundant information and improve the accuracy of defect detection. The specific calculation is:
[0045]
[0046] Where H and W are the height and width of the input image, x i,j is the value of the i,jth pixel in the image.
[0047] The present invention provides a method for detecting multiple types of surface defects of industrial products based on an improved YOLOv5 model.
[0048] Beneficial effects:
[0049] This method for detecting multiple types of surface defects in industrial products, based on an improved YOLOv5 model, employs a generative adversarial network to generate diverse, high-quality defect images. This significantly expands the training dataset, ensures a balanced distribution of data samples, and provides sufficient high-quality sample support for model training, thereby improving detection accuracy. Furthermore, by introducing a coordinated attention mechanism, the YOLOv5 backbone network is optimized, enhancing the model's ability to process spatial information in images. This effectively addresses the positional information loss caused by global pooling and improves the accuracy and efficiency of feature extraction. The use of a decoupled head detector further optimizes the independence of classification and regression tasks, reduces interference between tasks, and improves the model's convergence speed and detection accuracy.
[0050] PSF-TM adopts a strategy of gradually optimizing and fusing different sub-networks, enabling the defect detection model to be quickly migrated to different production scenarios and product types. This strategy can effectively improve the generalization ability of the model, enabling it to quickly adapt to new scenarios and maintain high-precision detection performance. Through data augmentation and feature mapping adjustment, PSF-TM optimizes the feature representation in the transfer learning process, enabling the model to perform efficiently in a variety of tasks and scenarios. Through multi-level feature detection modules and adaptive convolution kernels, the model accurately locates defects at different scales, and uses global average pooling technology to further improve detection accuracy, ensuring that the model not only meets the accuracy requirements, but also can operate efficiently under the real-time requirements of industrial production. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is a flowchart for implementing the invention. DETAILED DESCRIPTION
[0052] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 making creative efforts are within the scope of protection of the present invention.
[0053] like Figure 1As shown, an embodiment of the present invention provides a method for detecting multiple types of surface defects of industrial products based on an improved YOLOv5 model, including: S1. Constructing a surface defect dataset, using a deep learning generative adversarial network to generate defect images, using an improved deep convolutional generative adversarial network to expand the dataset, introducing a self-attention mechanism in the generator to improve the accuracy of the structure and details of the generated images, and introducing a channel attention mechanism in the discriminator to enhance the ability to distinguish between real images and generated images, thereby generating diverse and high-quality defect images. S1 specifically includes:
[0054] S1.1 uses a generative adversarial network to generate surface defect images. The generative adversarial network consists of a generator and a discriminator. The output of the generator G(z) is processed by the self-attention mechanism A gen To enhance the utilization of global information, the output D(x) of the discriminator is processed by the channel attention mechanism A dis Strengthen the dependencies between image channels to improve the quality of generated images:
[0055] G(z)=Gen(z,A gen )
[0056] D(x)=Dis(x,A dis )
[0057] S1.2 Label the generated defect images and ensure that the number of samples of each defect type in the dataset is balanced.
[0058] Labeling: Manual or automated labeling is performed on the generated images to ensure that each defect type, such as scratches, dents, and cracks, is correctly labeled. The label includes the defect type and its location in the image, such as the coordinates of the bounding box.
[0059] Sample balance: Based on the generation of each defect type, the generated images are processed to ensure that the number of samples for each defect type is balanced. Assume that the generated samples have three different defect types, and the image samples generated for each type are:
[0060] Type A: 500 sheets
[0061] Type B: 450 sheets
[0062] Type C: 550 sheets
[0063] If there are fewer samples of a certain type of defect, such as type B, and this affects the balance of the data set, data augmentation techniques (such as rotation, cropping, scaling, etc.) can be used to generate more samples so that the number of samples of each defect type reaches a predetermined balance.
[0064] S1.3 uses the generated high-quality defect images and real images to expand the dataset and provide sufficient training samples to support the subsequent training of deep learning models.
[0065] Dataset expansion: Combine the generated high-quality defect images with real images to form a larger dataset. Assuming the number of real image samples is 2,000 and the number of generated image samples is 5,000, the final training dataset will contain 7,000 images. This expansion improves model training performance, especially when samples are scarce.
[0066] Training data quality control: To ensure the validity of generated data, cross-validation techniques can be used to evaluate the quality of the dataset and ensure distribution consistency between generated images and real images. Poor quality of generated images can affect the learning effect of the model. Therefore, it is necessary to ensure consistency between generated images and real images at the visual and feature levels.
[0067] Supplementary data labels: Generated defect images must be annotated according to the labeling standards of real data to ensure that the labels of the generated images meet the requirements of subsequent model training. For example, if 5,000 images are generated, in addition to ensuring accurate labels for the generated images, accurate bounding box coordinates must be provided for each generated image.
[0068] S2. Improve the YOLOv5 model by adding a coordinated attention mechanism to the backbone network to address the position information loss problem caused by global pooling, improve feature extraction capabilities, and use a decoupled head detector to separate the classification and regression tasks, thereby improving the model's detection accuracy and convergence speed. S2 specifically includes:
[0069] S2.1 Adding a coordinated attention mechanism to the backbone network of YOLOv5 coord , by taking the position information P loc It is embedded into channel attention to enhance feature extraction capability and is implemented by the following formula:
[0070] A coord (P loc )=σ(W coord ·P loc )
[0071] Among them, W coord is the weight matrix, σ is the Sigmoid activation function, and Ploc is the input position information, which represents the spatial position of the target area. By coordinating the attention mechanism, the important information of the target area can be effectively retained, while suppressing background noise and improving the feature extraction ability of the network.
[0072] S2.2 Using the decoupled head detector H in the head component of YOLOv5de , respectively handling classification tasks and regression tasks:
[0073] H de =Cl(x)+Re(x)
[0074] The decoupled head detector consists of independent classification and regression branches. The classification branch consists of two layers of 3×3 convolutions and one layer of 1×1 convolution. The regression branch consists of a layer of 3×3 convolution followed by a residual connection and a layer of 1×1 convolution to optimize category prediction and bounding box regression, respectively.
[0075] S2.3 uses multi-scale feature fusion technology and combines high-resolution images for detection on a feature pyramid structure. The formula is as follows:
[0076]
[0077] Among them, F i is the feature map of layer i, α i is the scaling factor, scaling factor α i is a learnable parameter, which is normalized to:
[0078]
[0079] Among them, w i For the original learnable value of the weight of the feature map of the i-th layer, bilinear interpolation is used to maintain spatial continuity when the feature map is upsampled by 2× after multi-scale feature fusion.
[0080] The decoupled head detector separates the classification and regression tasks, allowing each task to be optimized independently to avoid interference between tasks, thereby improving the detection accuracy and convergence speed of the model. The classification task focuses on learning the category of the object, and the regression task focuses on learning the location of the object, ensuring that both tasks can be fully optimized. The separation of classification and regression tasks can independently optimize each task, thereby improving the overall detection accuracy and enabling faster convergence during training.
[0081] Assume that the training dataset used contains the following types of defects, and the sizes of these defects vary greatly. Using multi-scale feature fusion and high-resolution image input can help improve the performance of the model:
[0082] Scratches: Small in size and usually fine in features.
[0083] Depression: moderate in size, relatively distinct in features.
[0084] Cracks: long and small, irregularly distributed.
[0085] By fusion of multi-scale features, the model is able to better handle these three types of defects and accurately detect them even if their sizes vary greatly in the image.
[0086] S3. Introducing an improved transfer learning algorithm and proposing the Progressive Subnetwork FusionTransfer Model, this allows for rapid migration of surface defect detection models across different scenarios and products, improving the model's generalization capabilities and reducing the additional cost and workload associated with model conversion. S3 specifically includes:
[0087] S3.1 uses Progressive Subnetwork Fusion TransferModel in the transfer learning process, and gradually optimizes the subnetwork S i Learning strategies to improve the model's adaptability in different scenarios and products, specifically:
[0088]
[0089] Among them, λ i is the weight coefficient, S i is the i-th sub-network.
[0090] Suppose there are two subnetworks:
[0091] Sub-network S1 focuses on the detection of steel surface defects, and the training data includes scratches and cracks on the steel surface.
[0092] Sub-network S2 focuses on the detection of PCB surface defects, and the training data includes pad defects and circuit breaks on the PCB board.
[0093] Each sub-network is first trained independently and then fused through a step-by-step optimization strategy in PSF-TM, ultimately forming a transfer learning model that can be applied in different scenarios.
[0094] S3.2 performs data augmentation on the migration model and dynamically optimizes feature representation through feature mapping adjustments:
[0095]
[0096] in, For data augmentation operations, PSF-TM adopts a gradual fusion strategy to fuse different sub-networks. A sub-network is a small network for a specific scenario or task to enhance the generalization ability of the model and adapt to new scenarios and tasks more quickly and effectively. In PSF-TM, the gradual fusion strategy allows the model to share knowledge between multiple tasks while fine-tuning for specific tasks.
[0097] S4. Use the improved YOLOv5 model to detect surface defects and migrate its application to different production environments, ensuring the model's high accuracy and speed in real-time detection and adaptability to different defect types and production scenarios. S4 specifically includes:
[0098] S4.1 builds a multi-level feature detection module, extracts defect features of different scales in each layer of feature maps, and fuses them using the following formula:
[0099]
[0100] Among them, F i is the feature map of layer i, α i is the fusion weight coefficient of each layer, and m is the number of feature layers. Data example:
[0101] Input image size: 640×640
[0102] Multi-level feature maps extracted by YOLOv5: the first layer F1 is 320×320, the second layer F2 is 160×160, and the third layer F3 is 80×80.
[0103] After weighted fusion of these feature maps, the final comprehensive feature map Fmulti_scale is obtained, which contains feature information extracted from multiple scales.
[0104] Low-level feature maps: Contains detailed information, such as small objects or edge features. Low-level feature maps have higher spatial resolution.
[0105] Middle-layer feature map: contains more complex texture and shape features and is suitable for medium-sized objects.
[0106] High-level feature maps: Contains global information and are suitable for large object or scene-level features. High-level feature maps have low spatial resolution.
[0107] S4.2 uses a detection algorithm based on an adaptive convolution kernel to accurately locate defects of different scales and dynamically weight them based on different areas of the image:
[0108]
[0109] Among them, ω i is the weight of each feature map, Conv i is the convolution operation, F fused is the fused feature map, The final detection output is obtained by first extracting low-level, mid-level, and high-level feature maps through the YOLOv5 model. Then, the importance of each region in the image is calculated and the feature maps are weighted according to the region importance. The following strategies are used to calculate the weight of each region:
[0110] First, different weights are assigned based on region location. Assuming a convolutional feature map is used, different image locations may contribute differently to defect detection. Regions near object edges may have a stronger response, while background areas contribute less to defect detection. Finally, further convolution operations and feature fusion are performed on the weighted feature map to increase focus on key areas.
[0111] Specifically, a spatial weighting coefficient α is calculated for each position (i, j) in the convolution feature map. ij , which represents the "importance" of that location. Use position encoding to represent the weight of each region. For example, using Gaussian distribution for weighting, larger objects and defects will be given higher weights.
[0112]
[0113] in:
[0114] (x i ,y j ) are the coordinates of the i,j position.
[0115] (x center ,y center ) are the center coordinates of the image or object.
[0116] σ is the standard deviation, which controls how quickly the weight decays.
[0117] The threshold area is set to 1000 pixels. If the area of the object is larger than this value, the object is considered large; otherwise, the object is considered small.
[0118] For large objects:
[0119] Assume that the width of the large object is w = 50 pixels, and calculate the standard deviation: σ = 25.
[0120] Gaussian weighting has a wider range of influence, and the weight of the object is mainly distributed in a larger area.
[0121] For small objects:
[0122] Assume that the width of the small object is w = 10 pixels, and calculate the standard deviation: σ = 5.
[0123] Gaussian weighting has a smaller influence range, and the weight of an object is mainly concentrated in the area of the object itself.
[0124] Weighting based on defect area
[0125] The weighting coefficient is determined by the response of the defect area. The response value of the defect area is stronger than that of the background area. Therefore, according to the characteristic response value R of each area ij To calculate the weighting coefficient, for example, use the maximum response area to weight and pay more attention to the defect area.
[0126]
[0127] Among them, R ij is the feature response value in region (i, j), and max(R) is the maximum response value of the entire image. Regions with stronger responses will receive greater weights.
[0128] Weighting is performed on the channel dimension. The YOLOv5 model extracts features from different channels in each convolutional layer, and different channels contribute differently in different areas. A weight coefficient α is assigned to each channel. c , which represents the importance of each channel in feature extraction. The channel weight coefficient can be automatically learned through a channel attention mechanism (such as the SE module).
[0129] α c =σ(W c ·F c )
[0130] in:
[0131] σ is the activation function (such as Sigmoid), W c is the learned weight matrix, F c is the feature map of the c-th channel.
[0132] Comprehensive weighted formula
[0133] Combining spatial position weighting, defect area response weighting and channel weighting, a comprehensive weighting coefficient α is obtained ijc , which is based on a weighted combination of spatial location, defect region response and channel importance:
[0134]
[0135] Among them, α ij is the spatial position weight, α c is the channel weighting coefficient, R ij is the response value.
[0136] Weighted feature map
[0137] Using the above dynamic weighting coefficient α ijc , weight each feature map:
[0138]
[0139] in:
[0140] F ijc It is the feature corresponding to position (i, j) and channel c in the feature map F.
[0141] α ijc is the dynamic weighting coefficient corresponding to the position and channel.
[0142] In this way, more attention can be focused on important areas in the image (such as defect areas) while reducing the influence of unimportant areas, thereby improving the detection accuracy of the model.
[0143] S4.3 uses global average pooling to post-process the detection results to eliminate excessive redundant information and improve the accuracy of defect detection. The specific calculation is:
[0144]
[0145] Where H and W are the height and width of the input image, x i,j is the value of the i,jth pixel in the image.
[0146] For the detection of steel surface defects, an 80×80×256 feature map is obtained (80 is the height and width, 256 is the number of channels). The pixel value in each channel contains the characteristic response of the area.
[0147] Global average pooling: For each channel, the average value of all 80×80 positions is calculated. For example, for the feature map F1 of the first channel (c=1), its global average pooling value is:
[0148]
[0149] This computes a single value, GAP1, for each channel, and then performs the same operation on all 256 channels, ultimately outputting a 256-dimensional vector.
[0150] Post-processing optimization: Global average pooling effectively focuses on important feature areas in the image and eliminates irrelevant background information. For example, on a steel surface, the response of cracked areas is retained by the pooling process, while background noise is ignored, thereby improving detection accuracy.
[0151] While 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 these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A method for detecting multiple types of surface defects of industrial products based on an improved YOLOv5 model, characterized in that: include: S1. Construct a surface defect dataset, generate defect images using a deep learning generative adversarial network, and expand the dataset using an improved deep convolutional generative adversarial network. By introducing a self-attention mechanism in the generator, the structure and detail accuracy of the generated images are improved. A channel-wise attention mechanism is introduced in the discriminator to enhance the ability to distinguish between real and generated images, thereby generating diverse and high-quality defect images. S2. Improve the YOLOv5 model by adding a coordinated attention mechanism to the backbone network and using a decoupled head detector to separate the classification and regression tasks, thereby improving the model's detection accuracy and convergence speed. S3. Introducing an improved transfer learning algorithm and proposing the Progressive Subnetwork Fusion TransferModel to enable rapid migration of surface defect detection models across different scenarios and products. S4. Use the improved YOLOv5 model to detect surface defects and migrate its application to different production environments to ensure the high accuracy and speed of the model in real-time detection and adaptability to different defect types and production scenarios.
2. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 1 is characterized in that: S1 specifically includes: S1.1 uses a generative adversarial network to generate surface defect images, wherein the generative adversarial network consists of a generator and a discriminator, and the output G(z) of the generator is processed by a self-attention mechanism A gen To enhance the utilization of global information, the output D(x) of the discriminator is obtained through the channel attention mechanism A dis Strengthen the dependencies between image channels to improve the quality of generated images: G(z)=Gen(z,A gen ) D(x)=Dis(x,A dis ) S1.2 Label the generated defect images and ensure that the number of samples of each defect type in the dataset is balanced; S1.3 uses the generated high-quality defect images and real images to expand the dataset.
3. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 1, characterized in that: S2 specifically includes: S2.1 Adding a coordinated attention mechanism to the backbone network of YOLOv5 coord , by taking the position information P loc It is embedded into channel attention to enhance feature extraction capability and is implemented by the following formula: A coord (P loc )=σ(W coord ·P loc ) Among them, W coord is the weight matrix, σ is the Sigmoid activation function, and Ploc is the input position information, which indicates the spatial position of the target area; S2.2 Using the decoupled head detector H in the head component of YOLOv5 de , respectively handling classification tasks and regression tasks: H de =Cl(x)+Re(x) S2.3 uses multi-scale feature fusion technology and combines high-resolution images for detection on a feature pyramid structure. The formula is as follows: Among them, F i is the feature map of the i-th layer, α i is the scaling factor.
4. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 3 is characterized in that: The decoupled head detector in step S2.2 includes independent classification branches and regression branches. The classification branch consists of two layers of 3×3 convolutions and one layer of 1×1 convolution, and the regression branch consists of one layer of 3×3 convolutions followed by residual connections and one layer of 1×1 convolution.
5. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 4 is characterized in that: The scaling factor α described in step S2.3 i is a learnable parameter, which is normalized to: Among them, w i is the original learnable value of the weight of the feature map of the i-th layer.
6. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 1, characterized in that: S3 specifically includes: S3.1 uses Progressive Subnetwork Fusion Transfer Model in the process of transfer learning, and gradually optimizes the subnetwork S i Learning strategies to improve the model's adaptability in different scenarios and products, specifically: Among them, λ i is the weight coefficient, S i is the i-th sub-network; S3.2 performs data augmentation on the migration model and dynamically optimizes feature representation through feature mapping adjustments: in, It is a data enhancement operation.
7. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 6, characterized in that: The PSF-TM adopts a gradual fusion strategy to fuse different sub-networks, where the sub-network is a small network targeting a specific scenario or task.
8. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 7, characterized in that: The stepwise fusion strategy described in PSF-TM allows the model to share knowledge across multiple tasks while being fine-tuned for a specific task.
9. The method for detecting multiple types of surface defects of industrial products based on the improved YOLOv5 model according to claim 8, characterized in that: S4 specifically includes: S4.1 builds a multi-level feature detection module, extracts defect features of different scales in each layer of feature maps, and fuses them using the following formula: Among them, F i is the feature map of layer i, α i is the fusion weight coefficient of each layer, and m is the number of feature layers; S4.2 uses a detection algorithm based on an adaptive convolution kernel to accurately locate defects of different scales and dynamically weight them based on different areas of the image: Among them, ω i is the weight of each feature map, Conv i is the convolution operation, F fused is the fused feature map, is the final detection output; S4.3 uses global average pooling to post-process the detection results to eliminate excessive redundant information and improve the accuracy of defect detection. The specific calculation is: Where H and W are the height and width of the input image, x i,j is the value of the i,jth pixel in the image.
Citation Information
Cited By
Workpiece defect detection method based on model analysis
CN121053101A
Incremental defect detection method and system based on selective distillation
CN122116028A