A heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation
By employing a heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation, the problems of non-independent and identically distributed data and scarce anomalous samples in federated learning are solved. This achieves efficient anomaly detection under privacy protection, improving the model's detection performance and localization accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CENT SOUTH UNIV
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-09
AI Technical Summary
In federated learning, the non-independent and identically distributed data across factories leads to the performance loss of the global model, and the anomaly detection model has difficulty in obtaining enough anomaly samples, resulting in false positives and false negatives. Especially in PCB manufacturing, existing technologies are unable to achieve efficient cross-enterprise data sharing and accurate anomaly detection while protecting data privacy.
A heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation is adopted. By constructing a federated learning system, a pre-trained encoder with frozen parameters and a decoder to be trained are used. Combined with a feature decoupling module and an adversarial gradient perturbation mechanism, pseudo-anomaly masks and adversarial perturbation terms are generated during local training, the decoder parameters are updated, and a more discriminative global model is generated.
It significantly improves the accuracy and positioning precision of anomaly detection, reduces false detection and false negative rates, and adheres to privacy protection principles, avoiding the sharing of raw data and reducing communication overhead.
Smart Images

Figure CN122176377A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and deep learning, and in particular to a heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation. Background Technology
[0002] With the deepening development of smart manufacturing and Industry 4.0, big data technology plays a crucial role in improving the efficiency and yield of complex industrial processes such as printed circuit board (PCB) manufacturing. However, this production data, originating from different production lines and factories, often contains highly sensitive trade secrets and intellectual property. At the same time, many existing regulations, for security reasons, strictly regulate the cross-border flow and processing scope of data. This makes data sharing across enterprises and sites extremely difficult, resulting in the formation of "data silos" of valuable data from various factories.
[0003] Driven by deep learning, building efficient intelligent models using production data widely distributed across various manufacturing sites is key to achieving industrial upgrading. Therefore, how to conduct decentralized collaborative modeling while protecting corporate data sovereignty and trade secrets, and complying with the aforementioned laws and regulations, is an extremely challenging task.
[0004] The federated learning modeling paradigm proposed by McMahan et al. provides a feasible solution to this problem. Its main steps include initialization, local training, parameter uploading, and model aggregation. Unlike traditional centralized training methods, federated learning builds a joint model through model aggregation. In this paradigm, sensitive production data remains on the local factory server, with only non-sensitive model parameters exchanged between the server and the site. The primary goal of federated learning is to build a more powerful and better generalization-capable global model.
[0005] This federated learning approach enables joint modeling across factories; however, data discrepancies between different manufacturing sites lead to performance issues in the jointly built global model. This performance loss in the global model based on local data at each site is typically caused by non-independent and identically distributed data between sites. For example, in PCB manufacturing, a single factory may produce multiple products with significantly different appearances (such as fabrics with different textures or colors). Local models are prone to overfitting to these trivial product-specific features, causing them to misclassify unseen, normal products as anomalies during the inference phase—that is, generating false positives.
[0006] Besides the issue of non-independent and identically distributed PCB samples between different factories, another problem limiting the global model built by federated learning is the difficulty in obtaining anomalous feature samples for training. Compared to the massive amount of normal PCB sample data, anomalous PCB samples are diverse in type and scarce in number, making it difficult for the anomaly detection model to predict all defect types in advance. This makes it difficult for the model to accurately estimate the distribution boundary of normal data, resulting in a blurred decision boundary and an inability to identify subtle defects, i.e., missed detections. Summary of the Invention
[0007] To address the issues of false positives and false negatives in federated anomaly detection and to protect data privacy, this application provides a heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation.
[0008] This application provides a heterogeneous anomaly detection method based on feature decoupling and resistance to gradient perturbation, employing the following technical solution:
[0009] A heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation includes the following steps:
[0010] S1: Construct a federated learning system, which includes a central server and... A single site; for any given site Its training dataset is The central server contains a global dataset. ;
[0011] S2: Initialize the global model, which contains a pre-trained encoder with frozen parameters. A decoder with one parameter to be trained ;
[0012] S3: The total number of rounds is... Federal communications training, in each round of communications In the process, the site performs a local training step based on feature decoupling and adversarial gradient perturbation to obtain updated local decoder parameters. ;
[0013] S4: Parameter Upload and Aggregation, the client will upload and aggregate the updated local decoder parameters. The parameters are uploaded to the central server; the central server performs weighted aggregation on the received parameters and updates the global model parameters. And distribute to each client;
[0014] S5: Repeat steps S3 to S4 until the global model converges or the preset number of communication rounds is reached;
[0015] S6. Detect the samples using the trained global model.
[0016] Optionally, the local training step in step S3 specifically includes:
[0017] a. Feature Extraction and Preliminary Reconstruction: The encoder extracts the input image. k-th layer multi-scale features The decoder utilizes Multiscale features Encoder features of the reconstructed output And calculate the differences in encoder features to generate a pseudo-anomaly mask. ;
[0018] Where R represents the set of real numbers, B represents the batch size of the samples, C represents the number of input image channels, H represents the height of the image, and W represents the width of the image;
[0019] b. Feature Decoupling: A feature decoupling module is introduced into each layer of the decoder to calculate the mean of the feature maps of the current batch. and standard deviation To capture product-specific, trivial distributions; to mask the pseudo-anomaly Input convolutional layers learn to generate spatially adaptive scaling parameters. and bias parameters The scaling and bias parameters carry general discriminative semantics independent of the product; the features are denormalized and reconstructed using these parameters to generate decoupled features. Based on the pseudo-anomaly mask, a local loss function is obtained to update the local decoder parameters.
[0020] c. Adversarial Gradient Perturbation: Calculate the gradient direction of the basic reconstruction loss relative to the input features or model parameters, and generate an adversarial perturbation term based on the gradient direction. The perturbation term is then injected into the output features of the encoder to construct an additional adversarial example loss function;
[0021] d. Model optimization: Based on the local loss function described in b, an adversarial example loss function is obtained through backpropagation to further update the local decoder parameters. .
[0022] Optionally, in step a, a pseudo-anomaly mask is generated. The specific formula is:
[0023]
[0024] in, The upsampling function aligns the score map to a specific size. The pseudo-anomaly mask It needs to be upsampled to match the resolution of the input image for subsequent feature decoupling guidance.
[0025] Optionally, in step b,
[0026] Calculate the mean of the feature map of the kth batch. and standard deviation The specific formula is as follows:
[0027]
[0028] Scaling parameters and bias parameters The specific formula is as follows:
[0029]
[0030] The specific formula for the denormalization reconstruction performed by the feature decoupling module is as follows:
[0031]
[0032] in, For decoder number The original output features of the layer, where h and w are coordinates in the matrix. The values of the pseudo-anomaly mask at coordinates h and w. and These are the mean and standard deviation of the feature in the current batch, respectively; and They respectively use convolutional layers to extract pseudo-anomaly masks The scaling factor and bias factor learned in the process.
[0033] Optionally, in step c, the adversarial perturbation term generated by the adversarial gradient perturbation mechanism... The calculation formula is:
[0034]
[0035] in, Hyperparameters used to control the perturbation amplitude include the step size and amplitude of the perturbation. Reconstruct the loss function locally Relative to the gradient direction of the feature, This represents the L2 norm.
[0036] Optionally, the local loss function in step d is defined as:
[0037]
[0038] in, Let be the height and width of the pseudo-anomaly map at the k-th scale feature, respectively; and let the adversarial example loss function be defined as:
[0039]
[0040] in, To counteract disturbances, a constrained space is required. Indicates targeting from the dataset Samples obtained from sampling Calculate the expected value; the optimization process aims to force the decoder to... In the presence of simulated anomalous disturbances Even in the worst case, it can still minimize the feature reconstruction error.
[0041] Optionally, the encoder employs a WideResNet-50 network structure pre-trained on the ImageNet dataset and keeps the parameters frozen throughout the federated learning process; the decoder has a network structure symmetrical to the encoder, used to restore and reconstruct low-dimensional features.
[0042] In summary, this application includes the following beneficial technical effects:
[0043] 1. Significantly improved anomaly detection and localization performance under privacy protection. Compared with existing federated learning methods (such as FedAvg, FedProx, HarmoFL, etc.), this invention achieves optimal detection performance on various PCB products. Visualization results show that the anomaly heatmap generated by this invention is more accurate and can more clearly locate defect areas.
[0044] 2. Effectively Solves False Detection Problems Caused by Fine-Grained Heterogeneity. Addressing the issue of fine-grained feature heterogeneity caused by the production of multiple products (such as fabrics of different colors and textures) at the same site in industrial settings, this invention achieves significant results through a feature decoupling module. This invention can explicitly decouple invariant general features from sample-specific trivial noise. By filtering out the interference of these local trivial features, the model learns domain-invariant feature representations, thereby effectively preventing the misclassification of unseen normal product variations (such as normal fabrics of different colors) as abnormal, and reducing the false detection rate.
[0045] 3. Effectively alleviates the problem of missed detections caused by data scarcity. Addressing the issue of insufficient abnormal samples and a limited number of normal samples across clients, this invention enhances the model's discriminative ability through an adversarial gradient perturbation mechanism. During training, gradient-based adversarial noise is adaptively injected to simulate potential anomalous features. This adversarial regularization strategy forces the model to establish a more compact and sharper decision boundary around the limited number of normal samples, thereby significantly improving the model's sensitivity to subtle defects and preventing missed detections.
[0046] 4. This invention fully complies with the privacy protection principles of federated learning: each client only needs to upload model parameter updates to the server, without sharing the original image data. Unlike some methods that require transmitting local feature embeddings or maintaining a global memory bank, this invention avoids the risk of privacy leakage at the feature level, while also reducing communication overhead. Attached Figure Description
[0047] Figure 1 This is the overall flowchart of this application;
[0048] Figure 2 This is a performance comparison chart of the method in this application;
[0049] Figure 3 This is another performance comparison chart of the method in this application. Detailed Implementation
[0050] The following is in conjunction with the appendix Figure 1-3 This application will be described in further detail.
[0051] This application discloses a heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation, the specific steps of which are as follows:
[0052] S1: Assume there exists a set of sites in the federated learning system. For any given site Its training dataset is The goal of the federated PCB anomaly detection model is to train a global model using the site's local dataset and test it on a global test dataset. The test model determines whether there are abnormal locations in the sample and locates the locations where abnormalities occur. This applies to any site. The distribution of its data features is as follows The label distribution is denoted as The global dataset, feature distribution, and labels are denoted as and , respectively. and Because different sites have PCB samples produced by different factories, therefore for any site... Its data feature distribution satisfies Furthermore, because PCB samples with unusual characteristics are harder to obtain in factories already in production compared to normal samples, this presents challenges for any given site. The label distribution of the dataset needs to satisfy:
[0053]
[0054] and global test dataset Then it satisfies:
[0055] ;
[0056] S2: The global detection model is an encoder-decoder structure, denoted as follows: and ,in and These are the corresponding parameters. In commonly used PCB models for anomaly detection, parameters pre-trained based on ImageNet are typically used for initialization. Decoder parameters are learned through federated learning. In this embodiment, the encoder adopts a WideResNet-50 structure and freezes its parameters, while the decoder adopts a hierarchical structure similar to that of the encoder.
[0057] S3: Total operation of server and site One communication round. Set the current communication round variable to... The initial communication rounds are A total of N sites participate in the joint training. Once the number of connected sites meets the requirement, the local training process begins.
[0058] a: Server-side initial global model At the same time, the server sends parameters to each site. Parallel computing at the site;
[0059] For any site The site utilizes a local training dataset. Update decoder parameters ;
[0060] Site Parameters sent by the server Initialize the local decoder .
[0061] Site Sampling any one sample ,in Let R represent the batch size of the samples, the number of input image channels, the height of the image, and the width of the image, respectively. R represents the set of real numbers. Encoder Based on input samples ,extract Multiscale features ,in For the first Encoder layer The output sample features. Decoding then reconstructs the encoder features from the K multi-scale features: ;
[0062] Site Extracted decoder features and preliminary reconstruction using the encoder to extract input image Multiscale features The decoder attempts to reconstruct the feature. Obtain the pseudo-anomaly mask .
[0063]
[0064] in, The upsampling function aligns the score map to a specific size. .
[0065] b: In the decoder's... In the batch normalization layer, trivial distribution statistics are extracted, and the feature map of the current batch is calculated. mean and standard deviation These two statistics are considered to capture trivial distribution information such as product-specific style and texture:
[0066]
[0067] Where h and w are the coordinates in the pseudo-anomaly mask.
[0068] Learn the discriminative feature parameters. Use the generated pseudo-anomaly mask... The input is fed into a dedicated convolutional layer, which learns to generate two spatially adaptive parameters: scaling parameters. and bias parameters These two parameters carry general discriminative semantic knowledge that is independent of the product.
[0069] :
[0070] in, It is a convolutional layer.
[0071] Perform denormalization feature reconstruction. Using the parameters mentioned above, generate the final decoupled features using the following formula to replace the original decoder output:
[0072]
[0073] Therefore, the site in this invention Local loss function Defined as:
[0074]
[0075] in, These are the height and width of the pseudo-anomaly map for the k-th scale feature, respectively. Indicates the first A pseudo-anomaly mask at coordinates The value of . c. The second part of this invention is the adversarial gradient perturbation mechanism described in this invention. This mechanism aims to sharpen the decision boundary by injecting gradient-based noise into the training to simulate anomalies. The specific steps are as follows:
[0076] Calculate based on local loss function Input normal samples The underlying reconstruction loss is calculated through forward propagation of the encoder and decoder. .
[0077] Generate adversarial perturbation terms. Calculate the local loss function. The gradient direction relative to the model weights or features. Adversarial perturbations are generated based on this gradient direction. :
[0078]
[0079] in, Hyperparameters used to control the perturbation amplitude include the step size and amplitude of the perturbation. The value is the L2 norm. This perturbation represents the direction that most significantly increases the model reconstruction error, thus simulating potential anomalous features. In the implementation, the invention is set as follows: .
[0080] Inject perturbations and perform adversarial training. The generated perturbations... These features are injected into the encoder's output features to form hard samples.
[0081] Optimize the model boundary. Force the decoder to... Even in the presence of disturbances Even under these circumstances, it is still necessary to minimize the reconstruction error. The adversarial example loss function in this invention is:
[0082]
[0083] in, To counteract disturbances, a constrained space is required. Indicates targeting from the dataset Samples obtained from sampling Calculate the expected value; the optimization process aims to force the decoder to... In the presence of simulated anomalous disturbances Even in the worst case, it can still minimize the feature reconstruction error.
[0084] Based on the aforementioned adversarial objective function, a backpropagation algorithm combined with a local reconstruction loss function is used. To update local decoder parameters
[0085] S4: Increment the current communication round. The server sends the global model parameters to all... Update global decoder parameters for each site. Examine the performance of the global model using the site's validation and test datasets, and report the results to the server.
[0086] S5: Repeat the above steps and the local training steps until training is complete. Each communication round or global model can achieve the required performance.
[0087] S6: Detect samples using a pre-trained global model.
[0088] To verify the effectiveness of this invention, we compared the method of this application with six state-of-the-art federated learning methods (FedAvg, FedProx, MOON, HarmoFL, FedSAM, FedFA, and FedNSAM). In this invention, the main evaluation metrics for the anomaly detection model are the area under the image-level receiver operating feature curve (I-AUROC), the pixel-level receiver operating feature curve (P-AUROC), and the image-level macro precision (I-F1). The anomaly detection rate performance metrics for the anomaly detection model are I-AUROC and I-F1, while the anomaly localization metric is P-AUROC.
[0089] Figure 2 The example shown is in The performance of this invention and other compared federated learning methods on the PCB-AD dataset is shown. In this embodiment, the method of this invention achieves 84.88% I-AUROC, 89.80% P-AUROC, and 81.27% I-F1 performance. In comparison, the second-best performing HarmoFL method only achieves 83.01 (I-AUROC), 87.74% (P-AUROC), and 80.22% (I-F1). This invention improves the important anomaly detection metric I-AUROC by approximately 2.2%, and the anomaly location accuracy metric P-AUROC by 2.3%, demonstrating its ability to solve PCB anomaly detection.
[0090] In real-world production, verifying the scalability of federated learning methods is crucial for demonstrating their applicability to real-world scenarios. Therefore, in this embodiment, the invention increases the number of sites / factories to... and It was validated in large-scale scenarios, and the results are as follows: Figure 3 As shown. In Under extreme heterogeneity and data scarcity conditions, this invention achieved 84.30% I-AUROC performance, 88.62% P-AUROC performance, and 80.75% I-F1 performance. Compared to the second-best performing method, this invention delivers a 3.67% improvement in detection performance and a 2.35% improvement in anomaly localization performance. The results of the embodiments demonstrate that this invention has extremely strong robustness in large-scale industrial deployments.
[0091] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation, characterized in that: Includes the following steps: S1: Construct a federated learning system, which includes a central server and... A single site; for any given site Its training dataset is The central server contains a global dataset. ; S2: Initialize the global model, which contains a pre-trained encoder with frozen parameters. A decoder with one parameter to be trained ; S3: The total number of rounds is... Federal communications training, in each round of communications In the process, the site performs a local training step based on feature decoupling and adversarial gradient perturbation to obtain updated local decoder parameters. ; S4: Parameter Upload and Aggregation, the client will upload and aggregate the updated local decoder parameters. The parameters are uploaded to the central server; the central server performs weighted aggregation on the received parameters and updates the global model parameters. And distribute to each client; S5: Repeat steps S3 to S4 until the global model converges or the preset number of communication rounds is reached; S6. Detect the samples using the trained global model.
2. The heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation according to claim 1, characterized in that: The local training step in step S3 is specifically as follows: a. Feature Extraction and Preliminary Reconstruction: The encoder extracts the input image. k-th layer multi-scale features The decoder utilizes Multiscale features Encoder features of the reconstructed output And calculate the differences in encoder features to generate a pseudo-anomaly mask. ; Where R represents the set of real numbers, B represents the batch size of the samples, C represents the number of input image channels, H represents the height of the image, and W represents the width of the image; b. Feature Decoupling: A feature decoupling module is introduced into each layer of the decoder to calculate the mean of the feature maps of the current batch. and standard deviation To capture product-specific, trivial distributions; to mask the pseudo-anomaly Input convolutional layers learn to generate spatially adaptive scaling parameters. and bias parameters The scaling and bias parameters carry general discriminative semantics independent of the product; the features are denormalized and reconstructed using these parameters to generate decoupled features. The local loss function obtained based on the pseudo-anomaly mask. To update local decoder parameters ; c. Adversarial Gradient Perturbation: Calculate the gradient direction of the basic reconstruction loss relative to the input features or model parameters, and generate an adversarial perturbation term based on the gradient direction. This perturbation term is then injected into the encoder's output features to construct an additional adversarial example loss function. ; d. Model optimization: based on the local loss function described in b. The adversarial example loss function is obtained through backpropagation algorithm. To further update the local decoder parameters .
3. The heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation according to claim 2, characterized in that: In step a, a pseudo-anomaly mask is generated. The specific formula is: in, The upsampling function aligns the score map to a specific size. The pseudo-anomaly mask It needs to be upsampled to match the resolution of the input image for subsequent feature decoupling guidance.
4. The heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation according to claim 3, characterized in that: In step b, Calculate the mean of the feature map of the kth batch. and standard deviation The specific formula is as follows: Scaling parameters and bias parameters The specific formula is as follows: The specific formula for the denormalization reconstruction performed by the feature decoupling module is as follows: in, For decoder number The original output features of the layer, h and w are coordinates in The values of the pseudo-anomaly mask at coordinates h and w. and These are the mean and standard deviation of the feature in the kth batch, respectively; and They respectively use convolutional layers to extract pseudo-anomaly masks The scaling factor and bias factor learned in the process.
5. The heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation according to claim 4, characterized in that: In step c, the adversarial perturbation term generated by the adversarial gradient perturbation mechanism The calculation formula is: in, Hyperparameters used to control the perturbation amplitude include the step size and amplitude of the perturbation. For local loss function Relative to the gradient direction of the feature, This represents the L2 norm.
6. The heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation according to claim 5, characterized in that: The local loss function in step d Defined as: in, These represent the height and width of the pseudo-anomaly map for the k-th scale feature, respectively; adversarial example loss function. Defined as: in, To counteract disturbances, a constrained space is required. Indicates targeting from the dataset Samples obtained from sampling Calculate the expected value; the optimization process aims to force the decoder to... In the presence of simulated anomalous disturbances Even in the worst case, it can still minimize the feature reconstruction error.
7. The heterogeneous anomaly detection method based on feature decoupling and adversarial gradient perturbation according to claim 1, characterized in that: The encoder employs a WideResNet-50 network structure pre-trained on the ImageNet dataset and keeps its parameters frozen throughout the federated learning process; the decoder has a network structure symmetrical to the encoder, used to restore and reconstruct low-dimensional features.