Small sample defect detection method based on context awareness and foreground prototype guidance
By applying a context-aware and foreground prototype-guided few-shot detection method in industrial scenarios, this paper utilizes ResNet-50 and feature pyramid networks to extract multi-scale feature maps, and combines context information aggregation and foreground prototype guidance modules to solve the problem of low candidate box quality in few-shot defect detection, achieving efficient detection of new defect types.
Patent Information
- Application Number
- CN202511050581.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-29
- Publication Date
- 2025-12-12
AI Technical Summary
Existing small-sample target detection methods are not effective in defect detection tasks in industrial scenarios, especially in the early stages of the emergence of new defect types. The lack of sufficient training samples leads to overfitting of the detection model, making it difficult to adapt to the situation where the number of defect samples is scarce in actual production.
A few-shot detection method based on context awareness and foreground prototype guidance is adopted. Multi-scale feature maps are extracted by combining ResNet-50 network with feature pyramid network. The method enhances feature representation by combining context information aggregation module and foreground prototype guidance module. The method enhances feature representation by using cross attention mechanism, which solves the problem of low quality of candidate boxes generated by region proposal network.
It significantly improves detection accuracy in small sample cases, enhances the quality of candidate boxes generated by the region proposal network, maintains the detection accuracy of base class targets, and provides an effective solution for defect detection in small sample cases.
Smart Images

Figure CN121120494A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of computer vision, and in particular to a small sample defect detection method based on context perception and foreground prototype guidance. BACKGROUND
[0002] Deep learning target detection algorithms have been widely used in surface defect detection, greatly improving the detection effect. However, the industrial product production line strictly controls the rate of defective products, and it is difficult to collect a sufficient number of training samples. Existing defect detection methods mostly rely on a large number of labeled samples for model training, which is difficult to adapt to the situation of a small number of defect samples in actual production, especially in the early stage of new defect types, there are usually only a small number of labeled images available, which leads to the problem of overfitting of the detection model. Therefore, studying the efficient detection of defects under the condition of only a small number of labeled samples has become an important problem to be solved in the current defect detection field.
[0003] Existing small sample target detection methods are mainly divided into three categories: meta-learning based methods, two-stage fine-tuning based methods, and metric learning based methods. Meta-learning based methods extract general knowledge through task-level training, enabling the model to quickly adapt to new tasks, but the meta-learning method has high training complexity and limited performance in extreme low sample situations. The two-stage fine-tuning based method first learns a general feature representation on the base class data, and then fine-tunes part of the parameters using a small number of new class samples to quickly adapt to new classes. This method is simpler and more effective, and can also well guarantee the detection performance of the model on the base class. In metric learning, prototype learning has shown good results. The core idea is to calculate the corresponding prototype for each class. This prototype can capture effective features, and classify the query sample according to the distance between the query sample and these prototypes.
[0004] However, the current small sample target detection method is mainly aimed at the natural image field, and direct application in the defect detection task in the industrial scene does not work well. SUMMARY
[0005] The purpose of the present application is to overcome the shortcomings and deficiencies of the prior art, and to provide a small sample defect detection method based on context perception and foreground prototype guidance. The present application makes full use of existing samples in the case of sample scarcity, and improves the detection performance of the model in the case of small samples.
[0006] The present application is implemented by the following technical solutions:
[0007] A small sample defect detection method based on context perception and foreground prototype guidance
[0008] Step S1, acquiring a labeled defect dataset;
[0009] Step S2, dividing the base class and new class data set by category;
[0010] Step S3: the processing steps of the defect detection model are as follows:
[0011] Step S31: multi-scale feature maps (P2~P6 feature maps) of the input image are extracted by combining a ResNet-50 network with a feature pyramid network;
[0012] Step S32: key information in the context environment around the defect is extracted using a context information aggregation module, which is used to construct more discriminative defect feature representation;
[0013] Step S33: an offline foreground prototype guiding module is used to calculate a foreground prototype using a small amount of samples and enhance the foreground feature part of the feature in a fine-grained manner through a cross-attention mechanism, so as to solve the problem of low quality of the candidate frame generated by the region proposal network RPN in the case of small sample;
[0014] Step S34: the enhanced query image features are input into the RPN to generate a set of candidate regions; then the candidate region features are sent into the detection head to complete the classification and boundary frame regression of the defect target, and finally the detection results containing the defect category and position information are output;
[0015] Step S4: a two-stage fine-tuning method is adopted, the model is first trained on the base class data set, and then the model detection head parameters are fine-tuned on the new class data set, so as to improve the detection ability of the new class target as much as possible while maintaining the original class detection ability;
[0016] Step S5: the trained model is used for defect detection.
[0017] Further, in step 2, the base class and new class data set are specifically described as follows:
[0018] 1) The base class is a defect category with a large number of labeled samples, which is used for initial feature learning of the model;
[0019] 2) The new class is a defect category with only a small amount of labeled samples, which is used for model adaptation training in a small sample scenario; the defect categories of the base class and the new class do not overlap.
[0020] As a preferred, step 31, extracting multi-scale features of the input image includes the following steps:
[0021] 1) Extracting multi-level feature maps of the input image I through a ResNet-50 network;
[0022] 2) Adopting feature pyramid network to perform feature fusion from top to bottom on the multi-level feature maps; outputting multi-scale fusion features containing rich semantic information and spatial details. The formula definition of feature extraction is:
[0023] F = φ (ψ (I))
[0024] Where F represents the multi-scale features extracted from the input image; ψ (·) represents the ResNet-50 network used to extract image features; φ (·) represents the feature pyramid fusion transformation.
[0025] Further, in step 32, the key information in the context environment around the defect is extracted on the multi-scale feature map by using the context information aggregation module, and the processing steps of the context information aggregation module are as follows:
[0026] 1) First, the module calculates the position offset of each reference point, the attention weight and the V feature consistent with the input feature dimension through the learnable linear layer, and the formula is as follows:
[0027] Δp = W1·F + b1
[0028] A = softmax (W2·F + b2)
[0029] V = W3·F + b3
[0030] Where Δp represents the offset of the N reference points, A represents the attention weight of each reference point when the feature is aggregated, and V is the feature value consistent with the input feature dimension, which is used for weighted aggregation of features. W i and b i (i = 1, 2, 3) are learnable weights and biases.
[0031] 2) Next, using the calculated reference point offset, attention weight and V feature, the information in the feature map is aggregated by weighted sum to obtain more discriminative features F a , and the formula is as follows:
[0032]
[0033] Where A i represents the attention weight of the i-th reference point, and V (p + Δp i ) represents the feature value of the reference point position.
[0034] 3) Finally, in order to maintain effective transmission of information and avoid degradation problems in deep network, the module adds the aggregated feature F a to the original input feature F to obtain the final output feature F out , and the formula is as follows:
[0035] F out = F + F a
[0036] The context information aggregation module is applied to the higher layer feature outputs P4 and P5 of the FPN, because the P4 and P5 features have richer semantic information and larger receptive fields, enabling the model to more comprehensively understand the target and its surrounding environment.
[0037] Further, in step 33, the processing steps of the foreground prototype guidance module are as follows:
[0038] 331) First, the features of the support image RoI are obtained by the RoIAlign operation which contains foreground information; further, an element-wise multiplication operation is performed between the support image feature map and the corresponding RoI feature, which further enhances the foreground features of the support image The formula is expressed as:
[0039]
[0040]
[0041] wherein the symbol represents the RoIAlign operation, the real label box in the kth support image of the ith class. represents the feature vector extracted from the kth support image of the ith class using operation.
[0042] 332) Average all enhanced support image features to obtain a generalized foreground support feature P fg :
[0043]
[0044] 333) Use the cross-attention mechanism to enhance the query feature I q to obtain the enhanced query feature I' q . The formula is expressed as:
[0045]
[0046] For a given input P fg , W q , W k , W v represent the learnable weight matrix in the attention mechanism, which is used to convert the input into a query vector Q, a key vector K and a value vector V; d k represents the dimension of the key vector K.
[0047] Finally, the loss function of the method adopts the loss function of FasterRCNN, and the loss is mainly composed of the classification loss and the regression loss of RPN and FasterRCNN, and the calculation formula is as follows:
[0048]
[0049] 1) Classification loss:
[0050] In the loss function formula, when calculating the loss function of the RPN network, p i is the probability that the anchor predicts the target, is the real label corresponding to the anchor, and is 1 when there is a target or 0 when there is no target. is the binary cross-entropy loss. When calculating the loss function of the FasterRCNN network, p i is the target class predicted by the anchor, is the real class label corresponding to the anchor. is the multi-class cross-entropy loss.
[0051] 2) Regression loss:
[0052] t i indicates the center position and width and height information of the i th predicted frame of the model; indicates the coordinate parameters of the real annotation frame matched with the positive sample anchor frame; L reg Smooth L1 loss function is used to calculate the coordinate offset; is used to indicate whether the predicted frame is valid.
[0053] Compared with the prior art, the present application has the following advantages and effects:
[0054] The present application designs a context information aggregation module to explicitly add context information to the original feature map, and enhances the expression ability of the model to defect features in the form of auxiliary information.
[0055] The present application also designs a foreground prototype-based guidance module to enhance foreground features and highlight defect targets, thereby improving the quality of the candidate frame generated by the region proposal network in the case of insufficient samples.
[0056] The present application is superior to other small sample target detection algorithms, and the detection accuracy is significantly improved on new class targets with only a small amount of training samples, while maintaining the detection accuracy of base class targets, thereby providing an effective and novel solution for small sample defect detection.
[0057] The present application has significant advantages compared with existing small sample target detection methods when applied to small sample PCB defect detection, and has important application value. BRIEF DESCRIPTION OF DRAWINGS
[0058] Figure 1 Flow chart of the small sample defect detection method based on context awareness and foreground prototype guidance of the present application.
[0059] Figure 2 Structural diagram of the feature extractor of the present application.
[0060] Figure 3 Structural diagram of the context information aggregation module of the present application.
[0061] Figure 4 Structural diagram of the foreground prototype guidance module of the present application.
[0062] Figure 5 Overall framework diagram of the small sample defect detection method based on context awareness and foreground prototype guidance of the present application, containing two stages of base class pre-training and new class fine-tuning.
[0063] Figure 6 PCB defect detection result diagram of the detection method of the present application. DETAILED DESCRIPTION
[0064] The present application will be further specifically and in detail described below in combination with specific embodiments.
[0065] The present application discloses a small sample defect detection method based on context awareness and foreground prototype guidance, which is specifically applied to a PCB defect detection task, and a flow chart is shown in Figure 1 The detailed description of the specific implementation is as follows:
[0066] Step S1, obtaining a labeled PCB defect dataset;
[0067] Step S2, dividing the base class and new class datasets according to the categories, the base class dataset containing relatively rich common defect type images and corresponding label information, used for initial training of the model, and the new class dataset containing a small amount of rare or newly appearing defect type images and label information;
[0068] Step S3: the processing steps of the defect detection model are as follows:
[0069] Step S31: extracting multi-scale feature maps (P2~P6 feature maps) of the input image through a ResNet-50 network combined with a feature pyramid network;
[0070] P2~P6 are five levels of feature maps, wherein P2 corresponds to the original Figure 1 / 4 scale, used to capture fine structures; P3~P6 are sequentially reduced to 1 / 8, 1 / 16, 1 / 32, 1 / 64, gradually enhancing semantics and expanding the receptive field, forming a top-down pyramid for subsequent modules to perform parallel prediction on multi-scale targets.
[0071] Step S32: using the context information aggregation module to extract key information in the context environment around the defect for constructing more discriminative defect feature representation;
[0072] Step S33: using an offline foreground prototype guiding module to calculate a foreground prototype using a small amount of samples and enhance the foreground feature part in the feature in a fine-grained manner through the cross-attention mechanism to solve the problem of low quality of the candidate frame generated by the region proposal network RPN in the small sample case;
[0073] Step S34: inputting the enhanced query image feature into the RPN to generate a set of candidate regions; and then sending the candidate region feature into the detection head to complete the classification and boundary frame regression of the defect target, and finally outputting the detection result containing the defect category and position information;
[0074] Step S4: using a two-stage fine-tuning method, the model is first trained on the base class data set, and then the detection head parameters of the model are fine-tuned on the new class data set, so as to improve the detection ability of the new class target as much as possible while maintaining the original class detection ability;
[0075] Step S5: using the trained model for PCB defect detection.
[0076] In step 2, the base class and the new class data set are specifically as follows:
[0077] The base class is a PCB defect category with a large number of labeled samples, which is used for initial feature learning of the model;
[0078] The new class is a PCB defect category with only a small number of labeled samples, which is used for model adaptation training in a small sample scenario; the defect categories of the base class and the new class do not overlap.
[0079] The base class and the new class contain a total of 15 PCB defect categories, of which 10 defect categories are selected to constitute the base class data set, and the remaining 5 defect categories constitute the new class data set.
[0080] The feature extractor is specifically as shown in Figure 2 First, the input image is extracted to obtain multi-scale features, including the following steps:
[0081] 1) extracting multi-level feature maps of the input PCB image I through a ResNet-50 network;
[0082] 2) using a feature pyramid network to perform top-down feature fusion on the multi-level feature maps; outputting multi-scale fusion features containing rich semantic information and spatial details. The formula definition of feature extraction is:
[0083] F = φ (ψ (I))
[0084] where F represents the multi-scale features extracted from the input PCB image; ψ (·) represents the image feature extraction using the ResNet-50 network; φ (·) represents the feature pyramid fusion transformation
[0085] After feature extraction, the context information aggregation module is applied to the higher layer feature outputs P4 and P5 of the FPN, because P4 and P5 features have more rich semantic information and larger receptive field, which enables the model to more comprehensively understand the target and its surrounding environment.
[0086] In combination Figure 3 , the processing steps of the context information aggregation module are as follows:
[0087] 1) First, the module calculates the position offset of each reference point, the attention weight and the V feature consistent with the input feature dimension through a learnable linear layer, which is expressed as follows:
[0088] Δp = W1·F + b1
[0089] A = softmax (W2·F + b2)
[0090] V = W3·F + b3
[0091] where Δp represents the offset of the N reference points, A represents the attention weight of each reference point when aggregating features, and V is a feature value consistent with the input feature dimension, which is used for weighted aggregation of features. W i and b i (i = 1, 2, 3) are learnable weights and biases.
[0092] 2) Next, using the calculated reference point offset, attention weight and V feature, the information in the feature map is aggregated by weighted sum to obtain more discriminative features F a , which is expressed as follows:
[0093]
[0094] where A i represents the attention weight of the i-th reference point, and V (p + Δp i ) represents the feature value of the reference point position.
[0095] 3) Finally, in order to maintain effective transmission of information and avoid degradation problems in deep network, the module adds the aggregated features F a to the original input features F to obtain the final output features F out , which is expressed as follows:
[0096] Fout =F+F a
[0097] Combination Figure 4 The processing steps of the foreground prototype guidance module are as follows:
[0098] 1) First, features are obtained from the RoI features of the supporting image through the RoIAlign operation. It includes foreground information; furthermore, an element-wise multiplication operation is performed between the supporting image feature map and the corresponding RoI features to further enhance the foreground features of the supporting image. The formula is expressed as:
[0099]
[0100] Among the symbols Indicates the RoIAlign operation. The k-th supporting image of class i. Indicates use The operation extracts the feature vector from the k-th supporting image of the i-th class.
[0101] 2) Average all the enhanced support image features to obtain a generalized foreground support feature P. fg :
[0102]
[0103] 3) Use cross-attention mechanism to apply query feature I q The enhanced query feature I′ is obtained by performing the enhancement. q The formula is expressed as:
[0104]
[0105] Given input P fg W q W k W v This represents the learnable weight matrix in the attention mechanism, used to transform the input into a query vector Q, a key vector K, and a value vector V; d k This represents the dimension of the key vector K.
[0106] Furthermore, the embodiments of this disclosure employ a two-stage fine-tuning training strategy, which is divided into a base class training stage and a few-sample fine-tuning stage, with the corresponding network structure as follows: Figure 5 As shown.
[0107] The loss function of the method adopted is the loss function of Faster R-CNN, which mainly consists of the classification loss and regression loss of RPN and Faster R-CNN. The calculation formula is as follows:
[0108]
[0109] 1) Classification loss:
[0110] In the loss function, p i is the probability of the anchor predicting the target, is the real label corresponding to the anchor, which is 1 when there is a target or 0 when there is no target. is the binary cross-entropy loss. In the calculation of the loss function of the FasterRCNN network, p i is the target class predicted by the anchor, is the real class label corresponding to the anchor. is the multi-class cross-entropy loss.
[0111] 2) Regression loss:
[0112] t i represents the center position and width-height information of the i-th predicted box of the model; represents the coordinate parameters of the real annotation box matched with the positive sample anchor box; L reg Smooth L1 loss function is used to calculate the coordinate offset; is used to indicate whether the predicted box is valid.
[0113] The performance indicators for evaluating PCB defect detection are the average precision mean mAP commonly used in the field of object detection. mAP is the average of APs of various categories.
[0114] AP is a core indicator for measuring the detection accuracy of each category, and its calculation steps are as follows:
[0115] 1) Match the predicted box with the real box. For each predicted box, calculate its intersection over union IoU with the real box; the IoU formula is defined as:
[0116]
[0117] where A pred represents the area of the predicted box, and A gt represents the area of the real annotation box. Set a threshold K for IoU. When the IoU of the predicted box is greater than K, it is classified as a positive example TP, otherwise, when the IoU of the predicted box is less than K, it is classified as a negative example FP; FN is a positive example that is incorrectly classified as a negative example.
[0118] 2) AP is obtained by calculating the area under the Precision-Recall curve, where Precision represents the proportion of all results judged as positive examples by the model that are actually correct; Recall represents the proportion of all true positive examples that are correctly found by the model. The formula is:
[0119]
[0120] When K is 0.5, AP50 can be calculated, and mAP is the average of all class APs.
[0121] In order to more accurately evaluate the generalization ability and robustness of the model after training using only a small number of new class samples, the detection effect of the model on the new class (novel classes) and the base class (base classes) needs to be investigated respectively. Therefore, the average precision of the model on the new class is recorded as nAP (novel-class mAP), and the average precision of the model on the base class is recorded as bAP (base-class mAP). By calculating nAP and bAP respectively, the detection performance of the model on new class defects can be effectively measured, and whether the detection performance on base class defects can be maintained after training new class can be determined.
[0122] Table 1 and comparison of other small sample target detection algorithms in new class detection
[0123]
[0124] Table 1 shows the comparison results of the model with other small sample target detection algorithms under different new class training sample quantities K = 1, 2, 3, 5, 10 (per class). In order to comprehensively evaluate the performance of the model in new class detection, three different new class and base class division methods are used. The evaluation index used is nAP50. Compared with the original TFA model, the nAP50 of the present application is not as good as other methods in the 1-shot setting under new class division 1 and 2, but it achieves the best performance in all other settings, especially in the new class division 3, K = 10 setting, which improves by 10.04%. Table 1 shows that the present application has better detection performance in the detection of new classes of PCB surface defects with limited training samples compared with previous methods.
[0125] Table 2 and comparison of other small sample target detection algorithms in base class detection
[0126]
[0127]
[0128] Table 2 shows the bAP50 index of the algorithm of the present application on the base class. Although the present application is slightly lower than TFA, this decline in the detection performance of the base class may be due to the adaptation of the model to the new class, but compared with other methods, it still maintains a significant advantage in the base class detection task. The effectiveness of the method of the present application in the small sample defect detection scene.
[0129] In combination Figure 6 As shown in the method of the present application can better adapt to the small sample situation under the defect detection scene, for the missed detection, false detection, compared with the baseline model has been significantly improved. The method of the present application effectively improves the detection accuracy by using context information and enhanced foreground feature representation.
[0130] As described above, the present application can be better achieved.
[0131] The embodiments of the present application are not limited by the above examples, and any changes, modifications, substitutions, combinations, simplifications made without departing from the spirit and principles of the present application shall be equivalent replacement methods and shall be included in the protection scope of the present application.
Claims
1. A small-sample defect detection method based on context awareness and foreground prototype guidance, characterized in that... Includes the following steps: S1, Obtain the labeled defect dataset; S2, the dataset is divided into base class and new class categories; S3: Processing of the defect detection model; S4: A two-stage fine-tuning method is adopted. The model is first trained on the base class dataset, and then the parameters of the model's detection head are fine-tuned on the new class dataset. While maintaining the original class detection ability, the detection ability of the new class targets is improved. The loss function used is the Faster R-CNN loss function. S5: Use the trained model for defect detection.
2. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 1, characterized in that, The processing sub-steps of the defect detection model described in step S3 are as follows: S31: Extract multi-scale feature maps of the input image by combining the ResNet-50 network with the feature pyramid network; S32: Use a context information aggregation module on multi-scale feature maps to extract key information from the context surrounding the defect, in order to construct a more discriminative defect feature representation; S33: Use an offline foreground prototype guidance module to compute a foreground prototype using samples and enhance the foreground feature portion in a fine-grained manner through a cross-attention mechanism; S34: Input the enhanced query image features into the RPN to generate a set of candidate regions; then send the features of this set of candidate regions into the detection head to complete the classification of defect targets and bounding box regression.
3. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 2, characterized in that, Step S31, extracting multi-scale features from the input image, includes the following sub-steps: S311. Extract multi-level feature maps of input image I using the ResNet-50 network; S312. A feature pyramid network is used to perform top-down feature fusion on the multi-level feature maps; the output is a multi-scale fused feature containing rich semantic information and spatial details; features The extracted formula is defined as follows: F=φ(ψ(I)) I represents the input image; ψ(·) indicates that the ResNet-50 network is used to extract image features; φ(·) represents the feature pyramid fusion transformation; F represents the multi-scale features extracted from the input image.
4. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 2, characterized in that, The multi-scale feature map mentioned in step S31 refers to feature maps P2 to P6; P2 to P6 are feature maps at five levels. P2 corresponds to 1 / 4 scale of the original image and is used to capture fine structures. P3 to P6 decrease to 1 / 8, 1 / 16, 1 / 32 and 1 / 64 respectively, progressively enhancing semantics and expanding the receptive field, forming a top-down pyramid for subsequent modules to perform parallel prediction of multi-scale targets.
5. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 2, characterized in that, In step S2, the division of the dataset into base class and new class includes: The base class labels the defect categories of the samples, which are used for initial feature learning of the model; The new class of labeled samples is used for model adaptation training in small sample scenarios; The defect categories of the base class and the new class do not overlap; the number of labeled samples in the base class is greater than the number of labeled samples in the new class.
6. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 2, characterized in that, In step S32, the processing steps of the context information aggregation module are as follows: S321. First, the module calculates the position offset, attention weight, and V feature (with the same dimension as the input feature) for each reference point through a learnable linear layer, as shown in the following formula: Δp=W1·F+b1 A = softmax(W²·F + b²) V = W³·F + b³ Δp represents the offset of N reference points; A represents the attention weight of each reference point during feature aggregation; V represents the feature values with the same dimension as the input features, used for weighted aggregation of features; W i and b i (i = 1, 2, 3) are the learnable weights and biases; S322. Next, using the calculated reference point offset, attention weights, and V features, information from the feature maps is aggregated through a weighted sum to obtain more discriminative features F. a The formula is expressed as follows: A i This represents the attention weight of the i-th reference point; V(p+Δp i The eigenvalue represents the location of the reference point; S323. Finally, in order to maintain effective information transmission and avoid degradation problems in deep networks, the module uses residual connections to aggregate the features F. a Adding the original input feature F to the final output feature F yields the final output feature F. out The formula is expressed as follows: F out =F+F a 。 7. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 2, characterized in that, In step S32, a context information aggregation module is used on the multi-scale feature map, including: 1) No processing is performed on the P2, P3, and P6 feature maps of the multi-scale feature map; 2) For the higher-level feature outputs P4 and P5 feature maps of the multi-scale feature maps, a context information aggregation module is used to enhance the expressive power of the features.
8. The small-sample defect detection method based on context awareness and foreground prototype guidance according to claim 2, characterized in that, In step S33, the processing steps of the foreground prototype guidance module are as follows: S331. First, features are obtained from the RoI features of the supporting image through the RoIAlign operation. It contains foreground information; further, execution The element-wise multiplication operation between the feature and the corresponding RoI feature is used to further calculate the enhanced support image foreground features. The formula is expressed as: Indicates the RoIAlign operation; This represents the ground truth bounding box in the k-th supporting image of the i-th class; Indicates use The operation extracts the feature vector from the k-th support image of the i-th class; S332. Average all enhanced support image features to obtain a generalized foreground support feature P. fg : S333, Using cross-attention mechanism to apply query feature I q The enhanced query feature I′ is obtained by performing the enhancement. q The formula is expressed as: Given input P fg W q W k W v This represents the learnable weight matrix in the attention mechanism, used to transform the input into a query vector Q, a key vector K, and a value vector V; d k This represents the dimension of the key vector K; Finally, the enhanced feature I′ q The data is input into the detection head to obtain the classification results of defects and the regression results of target boxes.