A lightweight small target defect detection method for precision electronic products

By constructing a multi-order feature extraction and dual upsampling feature fusion network, combined with knowledge distillation technology, the problem of insufficient feature characterization and lightweight of the small-objective defect detection model is solved, and efficient defect detection effect is achieved.

CN119672439BActive Publication Date: 2025-07-18GUANGDONG UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411886100.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-07-18
Estimated Expiration
2044-12-20

AI Technical Summary

Technical Problem

When detecting small target defects, the feature characterization capability is insufficient, the model is too large to be deployed on mobile terminals or embedded devices, and the detection accuracy and speed are insufficient.

Method used

A multi-order feature extraction network and a dual upsampling feature fusion network are constructed, and the features of the teacher model are migrated to the lightweight model through knowledge distillation, enhancing the feature expression ability of the small-objective defect detection model and performing lightweight processing.

Benefits of technology

Improves the accuracy and speed of small-target defect detection, allowing models to run efficiently on mobile or embedded devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119672439B_ABST
    Figure CN119672439B_ABST
Patent Text Reader

Abstract

The present invention discloses a lightweight small target defect detection method for precision electronic products, including: constructing a defect detection model, extracting and fusing features of small target defects respectively through a multi-stage fusion backbone network and a double upsampling feature fusion network; taking the trained defect detection model as the teacher model, selecting the lightweight YOLOv8n-p2 model as the student model, selecting the feature layers to achieve knowledge transfer, enabling the student model to learn the features of the feature layers in the teacher model and imitate the teacher model to generate feature maps, performing knowledge distillation to obtain a lightweight defect detection model, and using the lightweight defect detection model to detect defects in the images to be detected of precision electronic products to obtain defect detection results. The present invention enriches the hierarchical features of small target defects, improves the detection accuracy, performs model lightweight processing through knowledge distillation, and enhances the effect of small target defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of defect detection, and more specifically, to a lightweight small target defect detection method for precision electronic products. Background Art

[0002] In the manufacturing process of some precision industrial products, especially in complex manufacturing processes, appearance defect detection is carried out at the loading stage of each process to ensure the product qualification rate and reduce subsequent production waste. For some defects with a relatively small size, since the target area is too small, it is difficult to observe with the naked eye. In the industry, the widely used detection methods mainly rely on automatic optical detection technologies such as traditional edge detection and template matching. However, this method highly depends on predefined templates and is difficult to effectively identify defect types outside the templates or slightly variant defects; at the same time, external factors such as fluctuations in lighting conditions and uneven image quality may lead to a decrease in the matching degree between the template and the image to be detected, thereby affecting the accuracy of the detection results; there are certain drawbacks in terms of detection flexibility, detection accuracy, detection speed, adaptability, and real-time performance.

[0003] In view of the above deficiencies, introducing object detection based on deep learning into the field of defect detection can overcome the limitations of traditional visual detection methods, further optimize the detection accuracy, and improve the detection efficiency. Generally, deep learning detection models use convolutional networks for downsampling to extract the features of target objects. However, for small target objects, after convolution, their feature maps are very small, the feature representation ability is insufficient, and the levels are not rich enough, resulting in low detection accuracy. Most models for detecting small targets have a large number of parameters in terms of calculation, cannot be deployed to run on mobile or embedded devices, or have too slow a running speed, thus affecting the detection efficiency. Therefore, it is necessary to lightweight the model. Therefore, how to improve the feature representation ability of industrial small target detection models and solve the model lightweighting is an urgent problem to be solved. Summary of the Invention

[0004] In order to solve the above technical problems, the present invention proposes a lightweight small target defect detection method for precision electronic products. By constructing a defect detection model, feature extraction and feature fusion are respectively carried out on small target objects, enriching the hierarchical features of small target defects, improving the expression ability of small target object features, enabling the model to further improve the detection accuracy in detecting small target defects, and lightweighting the model to improve the running speed of the small target defect detection model deployed on mobile or embedded devices.

[0005] The present invention provides a lightweight small target defect detection method for precision electronic products, including the following steps:

[0006] Obtain a small target defect dataset for precision electronic products, construct a defect detection model and train it using the small target defect dataset. The defect detection model includes a multi-stage feature extraction network and a double upsampling feature fusion network;

[0007] Use the multi-stage feature extraction network to perform multi-scale feature extraction and enhance features on small target defect images, generate multiple enhanced feature maps, and perform cross-scale feature fusion on the multiple enhanced feature maps through the double upsampling feature fusion network to generate a feature fusion map;

[0008] Perform object detection on each feature fusion map to obtain defect detection results. After iterative training, verify and test the defect detection results. When the model performance meets the standard, output the trained defect detection model;

[0009] Take the trained defect detection model as the teacher model, select the lightweight model YOLOv8n-p2 as the student model, and use knowledge distillation to transfer the feature layers of the teacher model to the student model. After distillation, obtain a lightweight defect detection model;

[0010] Collect the image data to be detected of precision electronic products, use the lightweight defect detection model to perform object detection on the image data to be detected, and output the defect detection results.

[0011] In this solution, in the defect detection model, the multi-stage feature extraction network consists of several 3×3 convolutional layers and a multi-stage gated feature module C2f-MogaBlock. The multi-stage gated feature module C2f-MogaBlock is formed by replacing the Bottlenet in C2f with a multi-stage gated aggregation module MogaBlock;

[0012] The double upsampling feature fusion network consists of several double upsampling splicing modules and multi-stage gated feature modules C2f-MogaBlock. The double upsampling splicing module is composed of an upsampling module using the nearest neighbor interpolation method and a feature recombination upsampling module in parallel.

[0013] In this solution, import the small target defect dataset into the defect detection model, use the multi-stage feature extraction network to obtain multi-scale features of the small target defect images and perform feature enhancement, generate multiple enhanced feature maps. Specifically:

[0014] The multi-stage gated aggregation module MogaBlock in the multi-stage gated feature module C2f-MogaBlock consists of a spatial aggregation block and a channel aggregation block. The spatial aggregation block includes a feature decomposition module and a multi-stage gated aggregation module;

[0015] In the feature decomposition module of the spatial aggregation block, the feature map first passes through a normalization layer. After the normalization process, a 1x1 convolutional layer is used to obtain local features, and then a global average pooling layer is used to obtain global features. The difference between the global feature and the local feature is multiplied by a scaling factor and added to the local feature. Finally, after passing through the GELU activation function, a multi-order feature map is obtained, completing the feature decomposition;

[0016] In the multi-order gated aggregation module of the spatial aggregation block, the multi-order feature map is divided into two branches. One branch passes through a 1x1 convolutional layer and then through the SiLU activation function to obtain an aggregation branch; the other branch passes through a 5x5 depth convolution and is then divided into three channels through a split layer. One channel remains unchanged, and the other two channels pass through 5x5 depth convolutions with a dilation rate of 2 and 7x7 depth convolutions with a dilation rate of 3 respectively to obtain three depth convolution feature maps. The three depth convolution feature maps are concatenated, and after concatenation, they pass through a 1x1 convolution and then through the SiLU activation function to obtain a context branch. The aggregation branch is multiplied by the context branch, passes through a 1x1 convolutional layer, and is added to the original input to obtain a multi-order gated feature map;

[0017] In the channel aggregation block, the multi-order gated feature map passes through a normalization layer, a 1x1 convolutional layer, a 3x3 depth convolutional layer, and the GELU activation function in sequence to obtain an optimized channel aggregation feature map. The optimized channel aggregation feature map passes through a 1x1 convolutional layer, and after calculation through the GELU activation function, it is subtracted from the original input optimized channel aggregation feature map. After subtraction, it is multiplied by a scaling factor and added to the original input optimized channel aggregation feature map to obtain a channel aggregation feature map. The channel aggregation feature map is added to the multi-order gated feature map to obtain a strengthened feature map.

[0018] In this solution, the calculation formula for the feature map passing through the multi-order gated aggregation module Mogablock is expressed as:

[0019] Y = X + SA(Norm(X))

[0020] Z = Y + CA(Norm(Y))

[0021] where X is the multi-order feature map obtained by feature decomposition, SA is the spatial aggregation block, Norm(·) is the normalization process, Y is the optimized channel aggregation feature map, CA is the channel aggregation block, and Z is the strengthened feature map.

[0022] In this solution, after using the multi-order feature extraction network to obtain multiple strengthened feature maps, the multi-scale feature fusion of multiple strengthened feature maps is performed through the double upsampling feature fusion network to generate a feature fusion map. Specifically:

[0023] Cross-scale feature fusion is performed on multiple enhanced feature maps through the double-upsampling splicing module and the multi-order gated feature module in the double-upsampling feature fusion network. The double-upsampling splicing module is composed of a nearest neighbor interpolation upsampling module and a feature recombination upsampling module through a parallel structure;

[0024] The multiple enhanced feature maps are divided into two branches and passed through the nearest neighbor interpolation upsampling module and the feature recombination upsampling module respectively to obtain upsampled feature maps with two interpolation methods. The upsampled feature maps are spliced through a Concat layer to obtain a spliced feature map, and the multi-order gated feature module is used to process the spliced feature map to obtain a feature fusion map.

[0025] In this solution, defect detection is performed on each fused feature map to output a defect detection result. After each round of cyclic training of the small target defect image samples, validation data is used to verify the detection and classification effect of the defect detection model. If the detection and classification effect meets the preset classification effect standard, the current network parameters are retained; otherwise, the network parameters are adjusted;

[0026] The generalization ability of the network is tested using the reserved test data. When the detection and classification performance of the defect detection model meets the preset classification performance standard, the network parameters at this time are used as the structure parameters of the defect detection model, and the trained defect detection model is output.

[0027] In this solution, the trained defect detection model is used as the teacher model, and the lightweight model YOLOv8n-p2 is selected as the student model. Knowledge distillation is used to transfer the feature layers of the teacher model to the student model. Specifically:

[0028] The trained defect detection model is used as the teacher model, and the lightweight model YOLOv8n-p2 is selected as the student model. Specified feature layers are selected from the teacher model as knowledge to be transferred to the specified layers of the student model;

[0029] The small target defect image samples are input into the student model, and the feature maps of the specified layers are calculated through forward propagation and saved. A 1×1 convolutional layer is used for feature alignment to make the feature maps of the student model and the teacher model have the same number of channels;

[0030] The feature maps of the teacher model and the student model are input into the MSE loss function to calculate the loss, and finally the sum is obtained as the distillation loss. Backpropagation is performed through the distillation loss to calculate the gradient, and the parameters of all layers of the student model are updated according to the calculated gradient until the model converges and the distillation is completed to obtain a lightweight defect detection model.

[0031] In this solution, the distillation loss function is expressed as:

[0032]

[0033] Where N, C, H, and W represent the batch size, the number of channels, the height of the feature map, and the width of the feature map respectively, represents the feature value of the student model at the position of height h and width w in the c-th channel of the i-th layer, represents the feature value of the teacher model at the position of height h and width w in the c-th channel of the i-th layer, and N represents the total number of feature layers.

[0034] In this solution, a vision detection device is used to collect the image data to be detected of precision electronic products, and the image data to be detected is preprocessed;

[0035] The preprocessed image data to be detected is input into a lightweight defect detection model to obtain multiple enhanced feature maps of the image data to be detected. A feature fusion map is generated through feature fusion, and a detection head is used to detect the feature fusion map, and the defect detection result of the image data to be detected is output.

[0036] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0037] Through a multi-stage feature extraction network and a double upsampling feature fusion network, the present invention extracts features, enhances, and performs multi-scale stitching and fusion on the image to be detected, performs target detection on the obtained fusion feature map, enriches the hierarchical features of small target defects, improves the expression ability of small target defect features, and further improves the detection accuracy of the model in detecting small target defects; through knowledge distillation, the knowledge of the small target defect detection model is transferred to a lightweight model, improving the running speed of the small target defect detection model deployed on mobile or embedded devices and enhancing the effect of small target defect detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments or exemplifications of the present invention, the following will briefly introduce the drawings required for use in the embodiments or exemplifications. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to these drawings shown.

[0039] Figure 1 Shows a flowchart of a lightweight small target defect detection method for precision electronic products;

[0040] Figure 2 Shows a flowchart block diagram of a multi-stage feature extraction network and a double upsampling feature fusion network in a defect detection model;

[0041] Figure 3 Shows a schematic flow diagram of a spatial aggregation block in a multi-stage gating aggregation module;

[0042] Figure 4 Shows the flow diagram of the channel aggregation block in the multi-stage gated aggregation module;

[0043] Figure 5 Shows the flow diagram of the double upsampling splicing module in the double upsampling feature fusion network. Detailed implementation manners

[0044] In order to more clearly understand the above objects, features and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific implementation manners. It should be noted that, without conflict, the embodiments of the present application and the features in the embodiments can be combined with each other.

[0045] In the following description, many specific details are set forth in order to fully understand the present invention. However, the present invention can also be implemented in other ways different from those described herein. Therefore, the protection scope of the present invention is not limited by the specific embodiments disclosed below.

[0046] As Figure 1 shown, an object detection method for lightweight small target defects of precision electronic products provided in an embodiment of the present invention includes:

[0047] S102, obtaining a small target defect data set of precision electronic products, constructing a defect detection model and training it using the small target defect data set, where the defect detection model includes a multi-stage feature extraction network and a double upsampling feature fusion network;

[0048] S104, using the multi-stage feature extraction network to perform multi-scale feature extraction and enhancement on the small target defect image, generating multiple enhanced feature maps, and performing cross-scale feature fusion on the multiple enhanced feature maps through the double upsampling feature fusion network to generate a feature fusion map;

[0049] S106, performing object detection on each feature fusion map, obtaining a defect detection result, validating and testing the defect detection result after iterative training, and outputting the trained defect detection model when the model performance meets the standard;

[0050] S108, using the trained defect detection model as a teacher model, selecting the lightweight model YOLOv8n-p2 as a student model, and transferring the feature layers of the teacher model to the student model using knowledge distillation, and obtaining a lightweight defect detection model after distillation;

[0051] S110, collecting the image data to be detected of precision electronic products, using the lightweight defect detection model to perform object detection on the image data to be detected, and outputting a defect detection result.

[0052] It should be noted that in the defect detection model, the multi-stage feature extraction network is composed of several 3×3 convolutional layers and multi-stage gated feature modules C2f-MogaBlock, where the multi-stage gated feature module C2f-MogaBlock is formed by replacing the Bottlenet in C2f with a multi-stage gated aggregation module MogaBlock; the double upsampling feature fusion network is composed of several double upsampling splicing modules and multi-stage gated feature modules C2f-MogaBlock, where the double upsampling splicing module is composed of an upsampling module by nearest neighbor interpolation and a feature recombination upsampling module in parallel, which perform upsampling on the input image respectively and splice them to output a spliced feature map; the multi-stage feature extraction network is used to extract multi-scale features of the image to be detected and perform feature enhancement to generate multiple enhanced feature maps; the double upsampling feature fusion network performs cross-scale feature fusion on multiple feature maps to generate a feature fusion map; target detection is performed on each fused feature map to output the target detection result.

[0053] Such as Figure 2As shown in the figure, the specific process of the defect detection model is as follows: A 3×3 convolutional layer is used to perform 3×3 convolutional feature extraction operations on the image to be detected, and the first convolutional feature map is output. The first convolutional feature map is subjected to multi-order gated aggregation calculations through a multi-order gated feature module, and the first enhanced feature map is output. After the first enhanced feature map is subjected to convolutional operations by a 3×3 convolutional layer, it is output to the multi-order gated feature module for multi-order gated aggregation calculations to generate the second enhanced feature map. After the second enhanced feature map is subjected to convolutional operations by a 3×3 convolutional layer, it is output to the multi-order gated feature module for multi-order gated aggregation calculations to generate the third enhanced feature map. After the third enhanced feature map is subjected to convolutional operations by a 3×3 convolutional layer, it is output to the multi-order gated feature module for multi-order gated aggregation calculations to generate the fourth enhanced feature map. The fourth enhanced feature map passes through a pooling layer to obtain a multi-scale feature map. The multi-scale feature map passes through a double upsampling and splicing module and then outputs the first upsampled feature map. The first upsampled feature map is spliced with the third enhanced feature map to generate the first spliced feature map. The first spliced feature map is output to the multi-order gated feature module to obtain the first enhanced spliced feature map. The first enhanced spliced feature map passes through a double upsampling and splicing module and then outputs the second upsampled feature map. The second upsampled feature map is spliced with the second enhanced feature map to generate the second spliced feature map. The second spliced feature map is output to the multi-order gated feature module to obtain the second enhanced spliced feature map. The second enhanced spliced feature map passes through a double upsampling and splicing module and then outputs the third upsampled feature map. The third upsampled feature map is spliced with the first enhanced feature map to generate the third spliced feature map. The third spliced feature map is output to the multi-order gated feature module to obtain the third enhanced spliced feature map. The third enhanced spliced feature map passes through a 3×3 convolutional layer, is spliced with the second enhanced spliced feature map, and is output to the multi-order gated feature module to obtain the first feature fusion map. The first feature fusion map passes through a 3×3 convolutional layer, is spliced with the first enhanced spliced feature map, and is output to the multi-order gated feature module to obtain the second feature fusion map. The second feature fusion map passes through a 3×3 convolutional layer, is spliced with the multi-scale feature map, and is output to the multi-order gated feature module to obtain the third feature fusion map. The third enhanced spliced feature map, the first feature fusion map, the second feature fusion map, and the third feature fusion map are respectively input into the detection head to obtain the detection results.

[0054] During the model training process, the small target defect dataset is imported into the defect detection model, and a multi-stage feature extraction network is used to obtain multi-scale features of the small target defect images and perform feature enhancement to generate multiple enhanced feature maps. The multi-stage gated aggregation module MogaBlock in the multi-stage gated feature module C2f-MogaBlock consists of a spatial aggregation block and a channel aggregation block, including a normalization layer, a 1x1 convolutional layer, a 3x3 depth convolutional layer, a GELU activation function layer, a SiLU activation function layer, and a GAP pooling layer. The spatial aggregation block includes a feature decomposition module and a multi-stage gated aggregation module; in the feature decomposition module of the spatial aggregation block, the feature map first passes through the normalization layer, and after normalization, the 1x1 convolutional layer is used to obtain local features, and then the global average pooling layer is used to obtain global features. The difference between the global features and the local features is multiplied by the scaling factor and added to the local features, and finally, after passing through the GELU activation function, a multi-stage feature map is obtained to complete the feature decomposition. The calculation formula is expressed as:

[0055] Y j =Conv 1×1 (Norm(X))

[0056] FD = GELU(Y j +γ s ⊙(Y j -GAP(Y j )))

[0057] where X is the input feature map, Y j represents the local feature, Norm(·) is the normalization process, FD represents the feature decomposition, γ s is the scaling factor, GELU is the GELU activation function, and GAP is the global average pooling layer.

[0058] As Figure 3 shown, in the multi-stage gated aggregation module of the spatial aggregation block, the multi-stage feature map is divided into two branches. One branch passes through the 1x1 convolutional layer and then passes through the SiLU activation function to obtain the aggregation branch; the other branch passes through the 5x5 depth convolution and is divided into three channels through the split layer. One channel remains unchanged, and the other two channels pass through the 5x5 depth convolution with a dilation rate of 2 and the 7x7 depth convolution with a dilation rate of 3 respectively to obtain three depth convolution feature maps, which are respectively expressed as Concatenate three deep convolutional feature maps. After concatenation, perform 1x1 convolution, and then pass through the SiLU activation function to obtain the context branch. Multiply the aggregation branch and the context branch, pass through a 1x1 convolutional layer, and add it to the original input to obtain a multi-stage gated feature map; The SiLU function serves as a gating signal to effectively fuse the aggregation branch and the context branch, achieving gating control. The multi-stage gated aggregation module captures features of different sizes through multi-stage deep convolutions and aggregates multi-stage features. The calculation formula is expressed as:

[0059]

[0060] Z r = SiLU(Conv 1×1 (X a )) ⊙ SiLU(Conv 1×1 (Y c ))

[0061] SA = Conv 1×1 (Z r )

[0062] Among them, the input X a is the multi-stage feature map obtained after feature decomposition, DWConv is the deep convolution, dilation and d are the parameter dilation rates in the deep convolution, Spilt is the split layer, S is the number of split layers, SiLU is the SiLU activation function, splitting out three channels 1, 2, 3, Y c is the channel concatenation feature map, SA is the spatial aggregation block, and Z r is the fusion feature map of the aggregation branch and the context branch.

[0063] As Figure 4 shown, in the channel aggregation block, pass the multi-stage gated feature map through the normalization layer, 1x1 convolutional layer, 3x3 deep convolutional layer, and GELU activation function in sequence to obtain the optimized channel aggregation feature map. Pass the optimized channel aggregation feature map through a 1x1 convolutional layer, and then subtract it from the original input optimized channel aggregation feature map after calculation by the GELU activation function. After subtraction, multiply it by the scale factor and add it to the original input optimized channel aggregation feature map to obtain the channel aggregation feature map. Add the channel aggregation feature map and the multi-stage gated feature map to obtain the enhanced feature map. The calculation is expressed as:

[0064] Y = GELU(DWConv 3×3 (Conv 1×1 (Norm(X a ))))

[0065] Z = Y + γ c ⊙ (Y - GELU(Conv 1×1 (Y)))

[0066] CA = Conv 1×1 (Z)

[0067] where X a is the multi - order feature map obtained by eigen - decomposition, CA is the channel aggregation block, γ c is the scale factor, Y is the optimized channel aggregation feature map, CA is the channel aggregation block, and Z is the enhanced feature map;

[0068] The calculation formula of the feature map passing through the multi - order gated aggregation module Mogablock is expressed as:

[0069] Y = X + SA(Norm(X))

[0070] Z = Y + CA(Norm(Y))

[0071] where X is the multi - order feature map obtained by eigen - decomposition, SA is the spatial aggregation block, Norm(·) is the normalization process, Y is the optimized channel aggregation feature map, CA is the channel aggregation block, and Z is the enhanced feature map.

[0072] After obtaining multiple enhanced feature maps using the multi - order feature extraction network, cross - scale feature fusion is performed on the multiple enhanced feature maps through the double up - sampling feature fusion network to generate a feature fusion map. Cross - scale feature fusion of the multiple enhanced feature maps is performed through the double up - sampling splicing module and the multi - order gated feature module in the double up - sampling feature fusion network, as Figure 5 shown. The double up - sampling splicing module is respectively composed of a nearest - neighbor interpolation up - sampling module and a feature recombination up - sampling module through a parallel structure. The multiple enhanced feature maps are divided into two branches and pass through the nearest - neighbor interpolation up - sampling module and the feature recombination up - sampling module respectively to obtain up - sampled feature maps of two interpolation methods. The up - sampled feature maps are spliced through the Concat layer to obtain a spliced feature map. The calculation formula is expressed as:

[0073] Y p = Concat(Upsample(Z), CARAFE(Z))

[0074] where Z is the enhanced feature map, Y p is the feature splicing map, Upsample represents the nearest - neighbor interpolation up - sampling module, CARAFE represents the feature recombination up - sampling module, and Concat represents the splicing module.

[0075] The multi - order gated feature module is used to process the spliced feature map to obtain a feature fusion map,

[0076] It should be noted that for each fused feature map, defect detection is performed and the defect detection results are output. After each round of cyclic training of the small target defect image samples, the validation data is used to verify the detection and classification effect of the defect detection model. If the detection and classification effect meets the preset classification effect standard, the current network parameters are retained; otherwise, the network parameters are adjusted. The generalization ability of the network is tested using the reserved test data. When the detection and classification performance of the defect detection model meets the preset classification performance standard, the network parameters at this time are used as the structural parameters of the defect detection model, and the trained defect detection model is output.

[0077] It should be noted that the trained defect detection model is used as the teacher model, and the lightweight model YOLOv8n-p2 is selected as the student model. The specified feature layers are selected from the teacher model and transferred as knowledge to the specified layers of the student model. Preferably, the feature layers of the teacher model that generate the third enhanced splicing feature map, the first feature fusion map, the second feature fusion map, and the third feature fusion map are selected, as well as the layers of the student model that receive the knowledge transfer. The small target defect image samples are input into the student model, and the feature maps of the specified layers are calculated through forward propagation and saved. The 1×1 convolutional layer is used for feature alignment to make the feature maps of the student model and the teacher model have the same number of channels. The feature maps of the teacher model and the student model are input into the MSE loss function to calculate the loss, and finally the sum is obtained as the distillation loss. Backpropagation is performed through the distillation loss to calculate the gradient, and the parameters of all layers (including the specified layers and other layers) of the student model are updated according to the calculated gradient until the model converges, and the lightweight defect detection model is obtained after distillation.

[0078] The distillation loss function is expressed as:

[0079]

[0080] where N, C, H, and W respectively represent the batch size, the number of channels, the height of the feature map, and the width of the feature map. represents the feature value at the position of height h and width w in the c-th channel of the i-th layer of the student model. represents the feature value at the position of height h and width w in the c-th channel of the i-th layer of the teacher model, and N represents the total number of feature layers.

[0081] According to an embodiment of the present invention, image data to be detected of a precision electronic product is collected by a vision detection device, and the image data to be detected is preprocessed; the preprocessed image data to be detected is input into a lightweight defect detection model to obtain multiple enhanced feature maps of the image data to be detected, a feature fusion map is generated through feature fusion, and a detection head is used to detect the feature fusion map to output a defect detection result of the image to be detected. Preferably, defect information of the image to be detected is supplemented to a small target defect dataset of the precision electronic product to periodically update the defect detection model. A defect detection database of the precision electronic product is constructed, and historical defect detection results are stored in the defect detection database. Defect features are generated according to category information, position information, and size information of the defects, and defect attribution is performed using production parameters corresponding to the defect information. The defect attribution information is matched with the defect features; the defect detection result of the current image to be detected is obtained, the defect features in the defect detection result are read, similarity calculation is performed using the defect features in the defect detection database, defect information meeting a preset similarity standard is screened, the defect attribution information of the screened defect information is extracted, operation and maintenance information of the production line equipment of the precision electronic product is generated according to the extracted defect attribution information, and the operation and maintenance personnel are reminded to perform equipment operation and maintenance management in a timely manner using the operation and maintenance information to avoid large-batch generation of defects and further improve the yield rate of the precision electronic product.

[0082] The lightweight defect detection model extracts features, enhances, and performs multi-scale stitching and fusion on the image to be detected of the precision electronic product through a multi-stage feature extraction network and a double upsampling feature fusion network, performs target detection on the obtained fusion feature map, enriches the hierarchical features of small target defects, improves the expression ability of small target defect features, and further improves the detection accuracy, detection speed, and detection effect of the model in the small target defect detection task.

[0083] Those of ordinary skill in the art will understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps including those of the above method embodiments. The foregoing storage medium includes various media that can store program codes, such as removable storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs. Alternatively, if the above integrated unit of the present invention is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiments of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the various embodiments of the present invention. The foregoing storage medium includes various media that can store program codes, such as removable storage devices, ROM, RAM, magnetic disks, or optical discs.

[0084] As described above, the above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should all be covered by the protection scope of the present invention.

Claims

1. A lightweight small target defect detection method for precision electronic products, characterized in that, It includes the following steps: Obtain a small target defect dataset of precision electronic products, construct a defect detection model and train it using the small target defect dataset. The defect detection model includes a multi-order feature extraction network and a double upsampling feature fusion network; Use the multi-order feature extraction network to perform multi-scale feature extraction and enhancement on small target defect images, generate multiple enhanced feature maps, and perform cross-scale feature fusion on the multiple enhanced feature maps through the double upsampling feature fusion network to generate a feature fusion map; Perform target detection on each feature fusion map to obtain defect detection results. After iterative training, verify and test the defect detection results. When the model performance meets the standard, output the trained defect detection model; Use the trained defect detection model as the teacher model, select the lightweight model YOLOv8n-p2 as the student model, and transfer the feature layers of the teacher model to the student model using knowledge distillation. After distillation, obtain a lightweight defect detection model; Collect the image data to be detected of precision electronic products, use the lightweight defect detection model to perform target detection on the image data to be detected, and output the defect detection results; In the defect detection model, the multi-order feature extraction network consists of several 3×3 convolutional layers and a multi-order gated feature module C2f-MogaBlock. The multi-order gated feature module C2f-MogaBlock is formed by replacing the Bottlenet in C2f with a multi-order gated aggregation module MogaBlock; The double upsampling feature fusion network consists of several double upsampling splicing modules and multi-order gated feature module C2f-MogaBlock modules. The double upsampling splicing module is composed of an upsampling module using the nearest interpolation method and a feature recombination upsampling module in parallel; After using the multi-order feature extraction network to obtain multiple enhanced feature maps, perform cross-scale feature fusion on the multiple enhanced feature maps through the double upsampling feature fusion network to generate a feature fusion map. Specifically: Perform cross-scale feature fusion on the multiple enhanced feature maps through the double upsampling splicing module and the multi-order gated feature module in the double upsampling feature fusion network. The double upsampling splicing module is composed of an upsampling module using the nearest interpolation method and a feature recombination upsampling module through a parallel structure; Divide the multiple enhanced feature maps into two branches and pass them through the upsampling module using the nearest interpolation method and the feature recombination upsampling module respectively to obtain upsampling feature maps with two interpolation methods. Concatenate the upsampling feature maps through a Concat layer to obtain a concatenated feature map, and use the multi-order gated feature module to process the concatenated feature map to obtain a feature fusion map.

2. The lightweight small target defect detection method for precision electronic products according to claim 1, wherein, Import the small target defect dataset into the defect detection model, use the multi-order feature extraction network to obtain multi-scale features of the small target defect images and perform feature enhancement, and generate multiple enhanced feature maps. Specifically: The multi-order gated aggregation module MogaBlock in the multi-order gated feature module C2f-MogaBlock consists of a spatial aggregation block and a channel aggregation block. The spatial aggregation block includes a feature decomposition module and a multi-order gated aggregation module; In the feature decomposition module of the spatial aggregation block, the feature map first passes through a normalization layer. After the normalization process, a 1x1 convolutional layer is used to obtain local features, and then a global average pooling layer is used to obtain global features. The difference between the global feature and the local feature is multiplied by a scaling factor and added to the local feature. Finally, after passing through the GELU activation function, a multi-order feature map is obtained, completing the feature decomposition; In the multi-order gated aggregation module of the spatial aggregation block, the multi-order feature map is divided into two branches. One branch passes through a 1x1 convolutional layer and then through the SiLU activation function to obtain an aggregation branch; the other branch passes through a 5x5 depthwise convolution and is divided into three channels by a splitting layer. One channel remains unchanged, and the other two channels pass through 5x5 depthwise convolutions with a dilation rate of 2 and 7x7 depthwise convolutions with a dilation rate of 3 respectively to obtain three depthwise convolution feature maps. The three depthwise convolution feature maps are concatenated, and after concatenation, they pass through a 1x1 convolution and then through the SiLU activation function to obtain a context branch. The aggregation branch is multiplied by the context branch, passes through a 1x1 convolutional layer, and is added to the original input to obtain a multi-order gated feature map; In the channel aggregation block, the multi-order gated feature map sequentially passes through a normalization layer, a 1x1 convolutional layer, a 3x3 depthwise convolutional layer, and the GELU activation function to obtain an optimized channel aggregation feature map. The optimized channel aggregation feature map passes through a 1x1 convolutional layer and then through the GELU activation function calculation. After subtracting from the original input optimized channel aggregation feature map, multiplying by a scaling factor and then adding to the original input optimized channel aggregation feature map to obtain a channel aggregation feature map. The channel aggregation feature map is added to the multi-order gated feature map to obtain a strengthened feature map.

3. A lightweight small target defect detection method for precision electronic products according to claim 2, characterized in that, The calculation formula for the feature map passing through the multi-order gated aggregation module Mogablock is expressed as: , , Among them, is the multi-order feature map obtained by feature decomposition, is the spatial aggregation block, is the normalization process, is the optimized channel aggregation feature map, is the channel aggregation block, is the enhanced feature map.

4. A lightweight small target defect detection method for precision electronic products according to claim 1, characterized in that, Defect detection is performed on each fused feature map, and the defect detection results are output. After each round of cyclic training of the small target defect image samples, validation data is used to verify the detection and classification effect of the defect detection model. If the detection and classification effect meets the preset classification effect standard, the current network parameters are retained; otherwise, the network parameters are adjusted; The generalization ability of the network is tested using the reserved test data. When the detection and classification performance of the defect detection model meets the preset classification performance standard, the network parameters at this time are used as the structural parameters of the defect detection model, and the trained defect detection model is output.

5. A lightweight small target defect detection method for precision electronic products according to claim 1, characterized in that, Taking the trained defect detection model as the teacher model and selecting the lightweight model YOLOv8n-p2 as the student model, the feature layer of the teacher model is transferred to the student model using knowledge distillation. Specifically: Taking the trained defect detection model as the teacher model and selecting the lightweight model YOLOv8n-p2 as the student model, a specified feature layer is selected from the teacher model as the knowledge to be transferred to the specified layer of the student model; The small target defect image samples are input into the student model, and the feature map of the specified layer is calculated through forward propagation and saved. A 1×1 convolutional layer is used for feature alignment to make the feature maps of the student model and the teacher model have the same number of channels; Input the feature maps of the teacher model and the student model into the MSE loss function to calculate the loss, and finally sum them up to obtain the distillation loss. Perform backpropagation through the distillation loss, calculate the gradients, and update the parameters of all layers of the student model according to the calculated gradients until the model converges. After distillation, a lightweight defect detection model is obtained.

6. The lightweight small target defect detection method for precision electronic products according to claim 5, wherein The distillation loss is expressed as: , Among them respectively represent batch size, number of channels, height of the feature map, and width of the feature map, represents the feature value of the student model at the th layer and the th channel, with height and width ; represents the feature value of the teacher model at the th layer and the th channel, with height and width ; represents the total number of feature layers.

7. A lightweight small target defect detection method for precision electronic products according to claim 1, characterized in that, Use a visual detection device to collect the image data to be detected of precision electronic products, and preprocess the image data to be detected; Input the preprocessed image data to be detected into the lightweight defect detection model, obtain multiple enhanced feature maps of the image data to be detected, generate a feature fusion map through feature fusion, and use the detection head to detect the feature fusion map to output the defect detection result of the image data to be detected.

Citation Information

Patent Citations

  • Image defogging method based on online knowledge distillation

    CN114565539A

  • Lightweight metal surface defect detection method based on double-source knowledge distillation

    CN117540779A