Attention mechanism-based face recognition diffusion denoising defense method
By adopting an attention-based face recognition diffusion denoising defense method, the problems of unstable training and complex defense in existing technologies are solved, achieving efficient and accurate adversarial example denoising and improving defense performance and generalization ability.
Patent Information
- Application Number
- PCT/CN2025/101099
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-05-21
- Filing Date
- 2025-06-16
- Publication Date
- 2026-11-26
AI Technical Summary
Existing GAN-based adversarial example defense methods are unstable during training, and existing diffusion models require multiple adjustments to noise intensity, making the defense process complex and time-consuming. Furthermore, existing methods ignore the impact of adversarial attacks on specific regions of the image, resulting in limited defense performance.
A face recognition diffusion denoising defense method based on attention mechanism is adopted. By constructing a face recognition diffusion denoising network, combining a feature extraction network, a conditional denoising diffusion model and an attention model, image distance constraints and attention mechanism are introduced, and an adaptive diffusion step size selection mechanism is used to optimize the loss function to improve the defense effect.
It improves the accuracy and stability of defense, reduces time overhead, and demonstrates significant defensive effects under various adversarial attacks, exhibiting excellent generalization ability and effectively preserving the semantic information and visual quality of images.
Smart Images

Figure CN2025101099_26112026_PF_FP_ABST
Abstract
Description
A face recognition diffusion denoising defense method based on attention mechanism Technical Field
[0001] This invention relates to the field of artificial intelligence security technology, and in particular to a face recognition diffusion denoising defense method based on attention mechanism. Background Technology
[0002] Current GAN-based adversarial example defense methods generally suffer from training instability and are prone to pattern collapse, failing to meet performance and reliability requirements in practical applications. Training a GAN is a complex process involving a dynamic game between two neural networks: a generator and a discriminator. This game requires maintaining a proper balance between the two during training; however, maintaining this balance is quite difficult in practice, leading to training instability. Imbalanced training may cause the generator to fail to learn the true distribution of the data, resulting in low-quality or repetitive samples.
[0003] Existing adversarial example defense methods based on diffusion models require adjusting the noise intensity multiple times for different datasets to achieve the best defense and denoising effect. This process is not only complex but also extremely time-consuming, because the ideal noise intensity is not constant but highly dependent on the specific dataset characteristics, the form of adversarial attack, and the desired defense effect.
[0004] Existing adversarial example denoising methods generally employ a comprehensive approach, uniformly denoising the entire image. However, this method overlooks a key characteristic of adversarial attacks: attacks are typically concentrated in specific regions of the image rather than being evenly distributed across the entire image. These key attack regions are often carefully selected by the attacker because they have a decisive impact on the model's final classification decision. Therefore, when the denoising process fails to specifically identify and process these key regions, the overall defense performance is limited.
[0005] LPIPS loss (Learned Perceptual Image Patch Similarity) is a method for measuring image similarity. LPIPS uses pre-trained deep networks (such as VGG and AlexNet) to extract multi-layer features from two images, and then calculates the distance between the corresponding layer features of the two images to evaluate the perceptual similarity between the images.
[0006] The Frechet Inception Distance (FID) score is a metric used to evaluate the performance of generative models, particularly image generation models. It measures the difference between the distribution of generated images and the distribution of real images, specifically by comparing features extracted using a pre-trained neural network (typically Inception v3). Generally, a lower FID score indicates that the generated images are closer to the distribution of real images, and the better the model's generative performance. Summary of the Invention
[0007] The purpose of this invention is to provide a face recognition diffusion denoising defense method based on an attention mechanism that solves the problems of unstable model training, long defense time, and decreased recognition rate of clean samples after defense.
[0008] To achieve the above objectives, the technical solution adopted by the present invention is as follows: a face recognition diffusion denoising defense method based on attention mechanism, comprising the following steps;
[0009] S1, Obtain the dataset X, including the clean sample set X. clean and adversarial sample set X adv X clean Clean sample x clean and X adv There is a one-to-one correspondence between the adversarial samples x0 in the middle;
[0010] S2, construct a face recognition diffusion denoising network, including a pre-trained face recognition model, a conditional denoising diffusion model, and an attention model;
[0011] The face recognition model includes a feature extraction network, which is used to extract deep features from the input image;
[0012] The conditional denoising diffusion model includes a forward denoising process and a reverse generation process;
[0013] The forward noise addition process is used to add noise to the adversarial example x0 step by step, generating a noisy image corresponding to each time step, where the noisy image at time step t is x0. t 1≤t≤T, where T is the optimal diffusion step size;
[0014] The reverse generation process is conditionally guided, starting from x T Noise is removed step by step over time, and a denoised image is generated at time step t. The final denoised image As a denoised sample, the It is obtained from the following formula;
[0015] ,
[0016] In the formula, , , These are the mean function, variance function, and standard deviation function for time step t, respectively. Here, λ represents the deep features extracted by the feature extraction network, and λ is a hyperparameter. for Norm, ϵ is random noise, It follows a standard normal distribution;
[0017] The attention model is used to analyze denoised samples. and clean sample x clean Extract the corresponding attention map , ;
[0018] S3, the total loss L of constructing the face recognition diffusion denoising network. total ;
[0019] ,
[0020] ,
[0021] In the formula, L attention L1 is the attention loss; L1 is the L1 loss between adversarial examples and denoised examples. lpips To compensate for the LPIPS loss between adversarial samples and denoised samples, To calculate the mean squared error, λ1 and λ2 are the first and second weight hyperparameters, respectively;
[0022] S4, based on the optimal diffusion step size T, use the dataset X to minimize L. total Train the face recognition diffusion denoising network until it converges to obtain the face recognition diffusion denoising model;
[0023] S5: Obtain the adversarial sample to be cleaned, and generate the corresponding denoised sample based on the face recognition diffusion denoising model.
[0024] Preferably, the attention model uses the gradient integral method to extract the attention map, specifically including steps Sa1~Sa3;
[0025] Sa1, select a deep network F and a completely black image as the baseline input x. baseline Use the denoised or clean sample as the actual input x;
[0026] Sa2, the attribution value IG of the i-th pixel in x i (x) is obtained from the following formula;
[0027] ,
[0028] For interpolation parameters, For x baseline The RGB value of the i-th pixel, x i Let be the RGB value of the i-th pixel in x. For deep networks;
[0029] Sa3 replaces the RGB value of the i-th pixel in the actual input x with the attribution value of the i-th pixel to obtain the attention map of x.
[0030] Preferably, L1, L lpips Calculate according to the following formulas respectively;
[0031] ,
[0032] In the formula, N is the total number of pixels in the adversarial sample x0. For adversarial examples The nth pixel in the middle, For denoised samples The nth pixel;
[0033] ,
[0034] In the formula, L lpips x0 and are extracted by a multi-layer feature extraction network H is calculated after analyzing the feature map. l W l w represents the total height and total width of the feature map extracted by the l-th layer feature extraction network, respectively. l The weights of the l-th layer feature extraction network are... Let x0 be the feature map of the l-th layer of the feature extraction network at height h and width w. for The feature map of the l-th layer feature extraction network has feature values at height h and width w, where 1 ≤ h ≤ H and 1 ≤ w ≤ W. This is an element-wise multiplication operation. It is an L2 norm.
[0035] As a preferred option, in S4, the training of the face recognition diffusion denoising network is specifically as follows:
[0036] With preset iteration rounds and batch sizes, the dataset X is input into the face recognition diffusion denoising network according to the batch size, and a total loss L is calculated for each batch. total The network parameters of the conditional denoising diffusion model are adjusted by backpropagation until the iteration rounds are obtained.
[0037] Preferably, the optimal diffusion step size T is adaptively generated through steps Sb1~Sb4;
[0038] Sb1, from the clean sample set X clean and adversarial sample set X adv Sample subsets of the same size from each sample. and ;
[0039] Sb2, set D different step sizes T1~T D The d-th step has a size of T. d , 1≤d≤D;
[0040] Sb3, let the diffusion step size be T d ,right The adversarial examples are generated by a conditional denoising diffusion model to form a denoised dataset. and calculate and FID score;
[0041] Sb4, T1~T D For each of the D FID scores, the step size with the smallest FID score is taken as the optimal diffusion step size T.
[0042] Compared with the prior art, the advantages of the present invention are as follows:
[0043] (1) The conditional denoising diffusion model of the present invention performs denoising processing of adversarial examples. During the training process of the conditional denoising diffusion model, image distance constraints are introduced. The image distance constraints are based on the conditional denoising diffusion model. and This ensures that the distance between the two elements in the feature space is small during the denoising process, thus preserving the semantic information in the image. By introducing image distance constraints, the conditional denoising diffusion model not only learns how to reconstruct the image during training but also controls the magnitude of the reconstruction error, which helps improve the quality and stability of the denoising results.
[0044] (2) This invention combines the attention mechanism with a conditional denoising diffusion model. By using the attention map (the region of interest in the denoised sample and adversarial sample) to guide the conditional denoising diffusion model in generating denoising results closer to clean samples, the method uses the difference between attention maps as a supervisory signal, prompting the conditional denoising diffusion model to learn how to effectively remove noise from the image while preserving key identity features, and reducing damage to clean regions. This effectively improves the accuracy of defense and reduces the impact on clean samples.
[0045] (3) Image quality constraints are also introduced, through L1, L lpips The L1 loss and LPIPS loss of the adversarial examples and denoised samples are calculated to constrain the denoised samples and ensure the visual quality of the denoised images. The L1 loss is used to measure the similarity between the adversarial examples and denoised samples in the pixel dimension, ensuring that the pixel-level differences between the two are not too large, thereby maintaining the visual consistency of the denoised images. The LPIPS loss is used to measure the similarity between the adversarial examples and denoised samples at the perceptual level. By capturing the differences in high-level semantic features, the key structural and detailed information of the original image is further preserved.
[0046] (4) Use an adaptive diffusion step size selection mechanism to shorten the time to obtain the best denoising results. This mechanism can calculate the best diffusion step size based on the characteristics of the dataset and the form of adversarial attacks, thereby significantly reducing time overhead while ensuring the denoising effect.
[0047] (5) This invention demonstrates significant defensive effects against various adversarial attacks and exhibits excellent generalization capabilities, such as FGSM, PGD, and ATA adversarial attack methods. Furthermore, its defensive effectiveness can be transferred to other face recognition models, including FaceNet, IR152, and IRSE50, in a plug-and-play manner. Attached Figure Description
[0048] Figure 1 is an overall framework diagram of the present invention;
[0049] Figure 2 shows a comparison of the denoising results of different defense methods;
[0050] Figure 3 shows a comparison of attention maps with and without the use of attention mechanisms;
[0051] Figure 4 shows another set of attention maps comparing whether or not attention mechanisms are used. Detailed Implementation
[0052] The present invention will be further described below with reference to the embodiments and accompanying drawings.
[0053] Example 1: Referring to Figure 1, a face recognition diffusion denoising defense method based on attention mechanism includes the following steps;
[0054] S1, Obtain the dataset X, including the clean sample set X. clean and adversarial sample set X adv X clean Clean sample x clean and X adv There is a one-to-one correspondence between the adversarial samples x0 in the middle;
[0055] S2, construct a face recognition diffusion denoising network, including a pre-trained face recognition model, a conditional denoising diffusion model, and an attention model;
[0056] The face recognition model includes a feature extraction network, which is used to extract deep features from the input image;
[0057] The conditional denoising diffusion model includes a forward denoising process and a reverse generation process;
[0058] The forward noise addition process is used to add noise to the adversarial example x0 step by step, generating a noisy image corresponding to each time step, where the noisy image at time step t is x0. t 1≤t≤T, where T is the optimal diffusion step size;
[0059] The reverse generation process is conditionally guided, starting from x T Noise is removed step by step over time, and a denoised image is generated at time step t. The final denoised image As a denoised sample, the It is obtained from the following formula;
[0060] ,
[0061] In the formula, , , These are the mean function, variance function, and standard deviation function for time step t, respectively. Here, λ represents the deep features extracted by the feature extraction network, and λ is a hyperparameter. for Norm, ϵ is random noise, It follows a standard normal distribution;
[0062] The attention model is used to analyze denoised samples. and clean sample x clean Extract the corresponding attention map , ;
[0063] S3, the total loss L of constructing the face recognition diffusion denoising network. total ;
[0064] ,
[0065] ,
[0066] In the formula, L attention L1 is the attention loss; L1 is the L1 loss between adversarial examples and denoised examples. lpipsTo compensate for the LPIPS loss between adversarial samples and denoised samples, To calculate the mean squared error, λ1 and λ2 are the first and second weight hyperparameters, respectively;
[0067] S4, based on the optimal diffusion step size T, use the dataset X to minimize L. total Train the face recognition diffusion denoising network until it converges to obtain the face recognition diffusion denoising model;
[0068] S5: Obtain the adversarial sample to be cleaned, and generate the corresponding denoised sample based on the face recognition diffusion denoising model.
[0069] In this embodiment, the attention model uses the gradient integral method to extract the attention map, specifically including steps Sa1~Sa3;
[0070] Sa1, select a deep network F and a completely black image as the baseline input x. baseline Use the denoised or clean sample as the actual input x;
[0071] Sa2, the attribution value IG of the i-th pixel in x i (x) is obtained from the following formula;
[0072] ,
[0073] For interpolation parameters, For x baseline The RGB value of the i-th pixel, x i Let be the RGB value of the i-th pixel in x. For deep networks;
[0074] Sa3 replaces the RGB value of the i-th pixel in the actual input x with the attribution value of the i-th pixel to obtain the attention map of x.
[0075] The L1, L lpips Calculate according to the following formulas respectively;
[0076] ,
[0077] In the formula, N is the total number of pixels in the adversarial sample x0. For adversarial examples The nth pixel in the middle, For denoised samples The nth pixel;
[0078] ,
[0079] In the formula, L lpipsx0 and are extracted by a multi-layer feature extraction network H is calculated after analyzing the feature map. l W l w represents the total height and total width of the feature map extracted by the l-th layer feature extraction network, respectively. l The weights of the l-th layer feature extraction network are... Let x0 be the feature map of the l-th layer of the feature extraction network at height h and width w. for The feature map of the l-th layer feature extraction network has feature values at height h and width w, where 1 ≤ h ≤ H and 1 ≤ w ≤ W. This is an element-wise multiplication operation. It is an L2 norm.
[0080] In this embodiment S4, the training of the face recognition diffusion denoising network is specifically as follows:
[0081] With preset iteration rounds and batch sizes, the dataset X is input into the face recognition diffusion denoising network according to the batch size, and a total loss L is calculated for each batch. total The network parameters of the conditional denoising diffusion model are adjusted by backpropagation until the iteration rounds are obtained.
[0082] The optimal diffusion step size T is adaptively generated through steps Sb1~Sb4.
[0083] Sb1, from the clean sample set X clean and adversarial sample set X adv Sample subsets of the same size from each sample. and ;
[0084] Sb2, set D different step sizes T1~T D The d-th step has a size of T. d , 1≤d≤D;
[0085] Sb3, let the diffusion step size be T d ,right The adversarial examples are generated by a conditional denoising diffusion model to form a denoised dataset. and calculate and FID score;
[0086] Sb4, T1~T D For each of the D FID scores, the step size with the smallest FID score is taken as the optimal diffusion step size T.
[0087] In this embodiment, S5 specifically involves: inputting the adversarial sample to be purified as a condition into the conditional denoising diffusion model in the face recognition diffusion denoising model; gradually adding Gaussian noise during the forward denoising process to generate a denoised image at each time step; and then gradually removing noise and restoring the identity information of the image during the reverse generation process to finally obtain the corresponding denoised sample.
[0088] Example 2: Referring to Figure 2, which shows the denoising effects of different defense methods, samples from the CelebA-HQ dataset are used. In the figure, columns one through seven represent, in order, clean samples, adversarial samples, the Defense-GAN method, the TVM method, the MagNet method, the DiffPure method, and the method of this invention. The comparison shows that the denoised samples generated by this invention can effectively recover the identity information in the clean image while maintaining high visual clarity. This indicates that this invention can effectively eliminate adversarial perturbations while better preserving the key information of the image, thus improving the defense accuracy.
[0089] Example 3: Referring to Figures 3 and 4, in order to study the generalization and defense effectiveness of the present invention against different adversarial attacks, the present invention was used to defend against various adversarial attacks. At the same time, the present invention was compared with some mainstream adversarial defense methods, and the performance of different defense methods was evaluated by the defense accuracy rate, resulting in Table 1.
[0090] Table 1. Defense accuracy of different defense methods on the CelebA-HQ dataset
[0091]
[0092] Table 1 lists FGSM, PGD, ATA, C&W, and DeepFool as five typical adversarial example generation methods. The results in Table 1 demonstrate that this invention exhibits significant defensive effects against various adversarial attacks and demonstrates excellent generalization ability, effectively improving the model's robustness under multiple adversarial attacks. Furthermore, this invention not only maintains a high recognition accuracy close to the original model in the absence of attacks, but also outperforms other defense methods in terms of accuracy against FGSM, ATA, and DeepFool.
[0093] To verify the impact of the model's attention mechanism on defense accuracy, we trained the conditional denoising diffusion model with and without the attention mechanism, and then performed denoising defense on adversarial samples generated by FGSM adversarial attacks on the CelebA-HQ dataset, resulting in Table 2.
[0094] Table 2. Defense accuracy with and without attention mechanisms
[0095]
[0096] As can be seen from the data in Table 2, the overall defense accuracy is higher when using the model attention mechanism than when not using it.
[0097] Additionally, Figures 3 and 4 show a comparison of attention maps between denoised samples generated using and without the attention mechanism. As can be seen from the figures, although some adversarial noise can be removed without the attention mechanism, the attention region of the face recognition model is still somewhat dispersed, showing a certain difference compared to the attention map of the clean image. However, after using the attention mechanism, the attention maps of the denoised image and the clean image show a higher similarity, allowing the face recognition model to extract features more effectively and thus improve the accuracy of recognition.
[0098] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A face recognition diffusion denoising defense method based on attention mechanism, characterized in that, Includes the following steps; S1, Obtain the dataset X, including the clean sample set X. clean and adversarial sample set X adv X clean Clean sample x clean and X adv There is a one-to-one correspondence between the adversarial samples x0 in the middle; S2, construct a face recognition diffusion denoising network, including a pre-trained face recognition model, a conditional denoising diffusion model, and an attention model; The face recognition model includes a feature extraction network, which is used to extract deep features from the input image; The conditional denoising diffusion model includes a forward denoising process and a reverse generation process; The forward noise addition process is used to add noise to the adversarial example x0 step by step, generating a noisy image corresponding to each time step, where the noisy image at time step t is x0. t 1≤t≤T, where T is the optimal diffusion step size; The reverse generation process is conditionally guided, starting from x T Noise is removed step by step over time, and a denoised image is generated at time step t. The final denoised image As a denoised sample, the It is obtained from the following formula; , In the formula, 、 、 These are the mean function, variance function, and standard deviation function for time step t, respectively. Here, λ represents the deep features extracted by the feature extraction network, and λ is a hyperparameter. for Norm, ϵ is random noise, It follows a standard normal distribution; The attention model is used to analyze denoised samples. and clean sample x clean Extract the corresponding attention map 、 ; S3, the total loss L of constructing the face recognition diffusion denoising network. total ; , , In the formula, L attention L1 is the attention loss; L1 is the L1 loss between adversarial examples and denoised examples. lpips To compensate for the LPIPS loss between adversarial samples and denoised samples, To calculate the mean squared error, λ1 and λ2 are the first and second weight hyperparameters, respectively; S4, based on the optimal diffusion step size T, use the dataset X to minimize L. total Train the face recognition diffusion denoising network until it converges to obtain the face recognition diffusion denoising model; S5: Obtain the adversarial sample to be cleaned, and generate the corresponding denoised sample based on the face recognition diffusion denoising model.
2. The face recognition diffusion denoising defense method based on attention mechanism according to claim 1, characterized in that, The attention model uses the gradient integral method to extract the attention map, specifically including steps Sa1~Sa3; Sa1, select a deep network F and a completely black image as the baseline input x. baseline Use the denoised or clean sample as the actual input x; Sa2, the attribution value IG of the i-th pixel in x i (x) is obtained from the following formula; , For interpolation parameters, For x baseline The RGB value of the i-th pixel, x i Let be the RGB value of the i-th pixel in x. For deep networks; Sa3 replaces the RGB value of the i-th pixel in the actual input x with the attribution value of the i-th pixel to obtain the attention map of x.
3. The face recognition diffusion denoising defense method based on attention mechanism according to claim 1, characterized in that, The L1, L lpips Calculate according to the following formulas respectively; , In the formula, N is the total number of pixels in the adversarial sample x0. For adversarial examples The nth pixel in the middle, For denoised samples The nth pixel; , In the formula, L lpips x0 and are extracted by a multi-layer feature extraction network H is calculated after analyzing the feature map. l W l w represents the total height and total width of the feature map extracted by the l-th layer feature extraction network, respectively. l The weights of the l-th layer feature extraction network are... Let x0 be the feature map of the l-th layer of the feature extraction network at height h and width w. for The feature map of the l-th layer feature extraction network has feature values at height h and width w, where 1 ≤ h ≤ H and 1 ≤ w ≤ W. This is an element-wise multiplication operation. It is an L2 norm.
4. The face recognition diffusion denoising defense method based on attention mechanism according to claim 1, characterized in that, In S4, the specific steps for training the face recognition diffusion denoising network are as follows: With preset iteration rounds and batch sizes, the dataset X is input into the face recognition diffusion denoising network according to the batch size, and a total loss L is calculated for each batch. total The network parameters of the conditional denoising diffusion model are adjusted by backpropagation until the iteration rounds are obtained.
5. The face recognition diffusion denoising defense method based on attention mechanism according to claim 1, characterized in that, The optimal diffusion step size T is adaptively generated through steps Sb1~Sb4. Sb1, from the clean sample set X clean and adversarial sample set X adv Sample subsets of the same size from each sample. and ; Sb2, set D different step sizes T1~T D The d-th step has a size of T. d , 1≤d≤D; Sb3, let the diffusion step size be T d ,right The adversarial examples are generated by a conditional denoising diffusion model to form a denoised dataset. and calculate and FID score; Sb4, T1~T D For each of the D FID scores, the step size with the smallest FID score is taken as the optimal diffusion step size T.
