Attack resisting method based on diffusion model
Through an adversarial attack method based on diffusion model, combined with multimodal object detection and segmentation large model, a stable diffusion model is used to add perturbation in the latent space to generate adversarial samples with high visual quality and migration capabilities, solving the adversarial in the existing technology The problem of insufficient visual quality and migration capabilities of the sample improves the robustness of the defense model.
Patent Information
- Application Number
- CN202411086904.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-08
- Publication Date
- 2024-11-29
AI Technical Summary
The prior art cannot take into account the visual quality, migration ability, and attack performance on defense models of the adversarial samples, and it is difficult to generate undetectable and effective adversarial samples.
Adopting an adversarial attack method based on diffusion model, predicting the detection frame of the image through a multimodal object detection model, using segmented large-scale models to generate masks, combining a stable diffusion model to add perturbation in the latent space, and introducing diffusion process and region selection strategy generation Against the sample, set the structure, migration, and classifier loss functions for optimization.
The generated adversarial samples have good visual quality and high migration capabilities, which can help build a more robust defense model, improving the effectiveness of adversarial attacks and the security of the model.
Smart Images

Figure CN119047536A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of adversarial attacks on image classification, and in particular relates to an adversarial attack method based on a diffusion model. Background Art
[0002] Deep learning technology has made significant progress in recent years, and deep neural networks have gradually become the preferred technology used in the field of computer vision. However, deep learning models are adversarial. Studies have shown that adding perturbations that are difficult for humans to detect to images can cause the most advanced deep learning models to output high-confidence erroneous results. In some fields with high security requirements, such as autonomous driving face recognition, military security, and general artificial intelligence. The existence of adversarial samples reveals the potential risks of the model and also hinders the practical application of these technologies. Adversarial attacks in images aim to study more advanced adversarial attack methods, with the goal of generating imperceptible adversarial samples to mislead deep neural networks. These adversarial samples not only help to evaluate the vulnerability of the model, but also help to build a more robust model. Therefore, studying imperceptible adversarial attack techniques is of great significance for verifying the security of the model and improving its robustness. Summary of the invention
[0003] In view of the above-mentioned deficiencies in the prior art, the present invention provides an adversarial attack method based on a diffusion model, which solves the problem that the existing methods cannot take into account the visual quality, migration ability and attack performance of adversarial samples on the defense model.
[0004] In order to achieve the above-mentioned invention object, the technical solution adopted by the present invention is: a method for resisting attacks based on a diffusion model, comprising the following steps:
[0005] S1. Obtain text and use a multimodal object detection model to predict the detection box corresponding to the text in the image;
[0006] S2, use the segmentation model to predict the mask corresponding to the detection box, and integrate the mask set to obtain the target area for the adversarial attack;
[0007] S3, obtain the image, and use the stable diffusion model to map the image to the latent space corresponding to the image, and save the latent vector of each step;
[0008] S4. Iterate the adversarial attack and add perturbations to the latent space. Combine the target area and the latent vector, and use the strategy of introducing the diffusion process and area selection into the adversarial attack to generate adversarial samples, completing the adversarial attack based on the diffusion model.
[0009] The beneficial effects of the present invention are: through an adversarial attack method based on a diffusion model, the prior knowledge of the stable diffusion model, the attention mechanism and the regional control are utilized to optimize the visual quality and black-box migration capability of the adversarial samples; because the disturbance added by the adversarial attack is difficult to detect, it can help build a more robust defense model and has a high practical value.
[0010] Furthermore, the S1 comprises the following steps:
[0011] S101, obtaining an image on which an adversarial attack is to be performed and a text label corresponding to the image;
[0012] S102: Use a multimodal object detection model to obtain detection boxes corresponding to text labels, and retain detection boxes that are larger than a preset threshold.
[0013] The beneficial effect of the above further scheme is that the present invention uses a multimodal target detection model that can take open set-based text as input and conveniently and efficiently predict the detection box corresponding to the text.
[0014] Furthermore, the S2 comprises the following steps:
[0015] S201, arranging the image and the detection frame obtained in S1, and aligning the position and size of the image and the detection frame;
[0016] S202, outputting a predicted mask set using a large segmentation model according to the image and detection frame processed in S201;
[0017] S203: Integrate the mask set into a single mask, and use the single mask as a target area for countermeasure attack.
[0018] The beneficial effect of the above further scheme is: the present invention uses the large segmentation model to obtain the detection box according to the text, predict the corresponding mask, combine the masks as the adversarial attack area, and use the masks to improve the structural similarity between the adversarial sample generated by the adversarial attack and the original image.
[0019] Furthermore, the S3 comprises the following steps:
[0020] S301, pre-training a stable diffusion model;
[0021] S302, acquiring an image, and using an encoder of a pre-trained stable diffusion model to map the image to a latent space corresponding to the image, perform forward diffusion and noise processing, and retain each intermediate latent vector.
[0022] Furthermore, the formula for forward diffusion noise addition is as follows:
[0023]
[0024] in, It is parameterized as The deterministic inverse sampling process, x t represents the potential vector of time step t, and x0 represents the potential vector of the original image output by the encoder;
[0025] The above further scheme has the following beneficial effects: the present invention introduces the diffusion process into the adversarial attack, and can utilize the prior knowledge in the stable diffusion model. Adding disturbances in the latent space can bring a larger attack space to the adversarial attack. The latent vectors of each intermediate step are retained to control the detailed structure of the perturbed image in the subsequent optimization process. Decoding after the inverse diffusion process can change the semantic information of the image and improve the migration ability of the adversarial sample.
[0026] Furthermore, the S4 comprises the following steps:
[0027] S401, iterative adversarial attack, and adding disturbances to the latent space during the reverse diffusion denoising process;
[0028] S402, setting a structural loss function;
[0029] S403, setting a migration loss function;
[0030] S404, setting a classifier loss function;
[0031] S405. Construct an objective function, use the weights of the structural loss function, the weights of the transfer loss function, and the weights of the classifier loss function, jointly optimize the structural loss function, the transfer loss function, and the classifier loss function, use the decoder of the pre-trained stable diffusion model to decode the latent vector obtained by the objective function to generate an adversarial sample, and complete the adversarial attack based on the diffusion model.
[0032] The beneficial effect of the above further scheme is: the present invention adds perturbations to the latent space in the inverse denoising process, sets a structural loss function to improve the detail similarity of adversarial samples, a transfer loss function to improve the transfer ability of adversarial samples, and a classifier loss function to improve the adversarial nature of adversarial samples, and finally jointly optimizes the structural loss function, the transfer loss function and the classifier loss function, and uses the strategy of introducing diffusion process and region selection into adversarial attacks to generate adversarial samples with good visual quality and high transfer ability, and achieve a higher fooling rate on the defense model.
[0033] Furthermore, the structural loss function formula is as follows:
[0034] L1=MSE(S t ',S t )
[0035] Among them, L1 represents the structural loss function, MSE(·) represents the mean square error, S t ' represents the self-attention matrix of the latent vector after perturbation, S t Indicates the corresponding S t 'The unperturbed latent vector self-attention matrix at time steps;
[0036] The migration loss function formula is as follows:
[0037]
[0038] Where L2 represents the migration loss function, Var(·) represents the calculation variance, N represents the total number of reverse diffusions, and x t represents the latent vector at the t-th step in reverse diffusion, Cross(·) represents the accumulated cross attention during reverse reconstruction, P represents the textual prompt corresponding to the image, and SDM represents the stable diffusion model;
[0039] The formula of the classifier loss function is as follows:
[0040]
[0041] Among them, L3 represents the classifier loss function, J(·) represents the cross entropy loss, x represents the original input image, and x′ represents the model after the adversarial attack. The generated perturbation image, M represents the target area of the adversarial attack, and y represents the label category;
[0042] The objective function formula is as follows:
[0043]
[0044] Among them, x t represents the potential vector for attack, argmin(·) represents the parameter value when the function reaches the minimum, L represents the objective function, L1 represents the structural loss function, L2 represents the transfer loss function, L3 represents the classifier loss function, a represents the weight of the structural loss function, b represents the weight of the transfer loss function, and c represents the weight of the classifier loss function. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 The figure is a flow chart of the method of the present invention.
[0046] Figure 2 This is a diagram of the method architecture of the present invention.
[0047] Figure 3 This is a visual illustration of multimodal target detection in this embodiment.
[0048] Figure 4This is a flowchart of text prompt segmentation in this embodiment. DETAILED DESCRIPTION
[0049] The specific implementation modes of the present invention are described below so that those skilled in the art can understand the present invention. However, it should be clear that the present invention is not limited to the scope of the specific implementation modes. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations utilizing the concept of the present invention are protected.
[0050] Example
[0051] like Figure 1 and Figure 2 As shown, the present invention provides a method for resisting attacks based on a diffusion model, and its implementation method is as follows:
[0052] S1. Get the text and use the multimodal object detection model to predict the detection box corresponding to the text in the image. The implementation method is as follows:
[0053] S101, obtaining an image on which an adversarial attack is to be performed and a text label corresponding to the image;
[0054] S102: Use a multimodal object detection model to obtain detection boxes corresponding to text labels, and retain detection boxes that are larger than a preset threshold.
[0055] In this embodiment, Figure 3 As shown, Figure 3 To visualize the detection box and the image, the image and the open set-based text are used as input, and the multimodal object detection model is used to obtain the image detection box related to the text, and the obtained detection box is used as the input of step S2.
[0056] In this embodiment, the multimodal object detection model is the existing model Grounding DINO (Liu S, Zeng Z, Ren T, et al. Grounding DINO: Marrying DINO with grounded pre-training for open-set object detection[J].arXiv preprint arXiv:2303.05499,2023.).
[0057] S2, use the segmentation model to predict the mask corresponding to the detection box, and integrate the mask set to obtain the target area for the attack, such as Figure 4 As shown, the implementation method is as follows:
[0058] S201, arranging the image and the detection frame obtained in S1, and aligning the position and size of the image and the detection frame;
[0059] S202, outputting a predicted mask set using a large segmentation model according to the image and detection frame processed in S201;
[0060] S203: Integrate the mask set into a single mask, and use the single mask as a target area for countermeasure attack.
[0061] In this embodiment, the detection box obtained in step S1 is used as input, and the mask corresponding to the detection box prompt is obtained using the selected large segmentation model. Each detection box corresponds to a mask, and then all the masks are merged as the disturbance-added area M to improve the structural similarity between the adversarial sample and the original image.
[0062] In this embodiment, the segmentation model is the existing model Segment Anything Model (Kirillov A, Mintun E, Ravi N, et al. Segment anything[C]. Proceedings of the IEEE International Conference on Computer Vision(ICCV), 2023:4015-4026.).
[0063] S3. Get the image, and use the stable diffusion model to map the image to the latent space corresponding to the image, and save the latent vector of each step. The implementation method is as follows:
[0064] S301, pre-training a stable diffusion model;
[0065] S302, acquiring an image, and using an encoder of a pre-trained stable diffusion model to map the image to a latent space corresponding to the image, perform forward diffusion and noise processing, and retain each intermediate latent vector;
[0066] The formula for forward diffusion noise addition is as follows:
[0067]
[0068] in, It is parameterized as The deterministic inverse sampling process, x t represents the potential vector of time step t, and x0 represents the potential vector of the original image output by the encoder.
[0069] In this embodiment, a trained open source stable diffusion model SDM is used. The stable diffusion model is pre-trained on a large number of image-text pairs.
[0070] In this embodiment, a trained encoder is used to map an image into a latent space; for an original image x, the encoder ε is used to encode the image into a latent vector z=ε(x).
[0071] In this embodiment, the encoded latent vector is subjected to t times of forward diffusion and noise addition, and the intermediate latent vector x in the diffusion process is retained. t-1 ,...,x1, used in step S4 to improve the detail similarity of adversarial samples using self-attention.
[0072] S4, iterate the adversarial attack and add disturbances to the latent space, and combine the target area and the latent vector to generate adversarial samples by introducing the diffusion process and area selection into the adversarial attack strategy. The implementation method is as follows:
[0073] S401, iterative adversarial attack, and adding disturbances to the latent space during the reverse diffusion denoising process;
[0074] S402, setting a structural loss function;
[0075] S403, setting a migration loss function;
[0076] S404, setting a classifier loss function;
[0077] S405. Construct an objective function, use the weights of the structural loss function, the weights of the transfer loss function, and the weights of the classifier loss function, jointly optimize the structural loss function, the transfer loss function, and the classifier loss function, use the decoder of the pre-trained stable diffusion model to decode the latent vector obtained by the objective function to generate an adversarial sample, and complete the adversarial attack based on the diffusion model.
[0078] In this embodiment, the latent vector is subjected to inverse diffusion denoising, and the decoder D can reconstruct the latent vector z into an image x0=D(z)=D(ε(x)), and the reconstructed image is close to the original image.
[0079] In this embodiment, perturbations are iterated and added in the latent space to ensure the similarity between the adversarial sample and the original image after final decoding, that is, the imperceptibility of the perturbation; a joint loss function is set to respectively enhance the detail similarity, transferability and adversarial nature of the adversarial sample.
[0080] In this embodiment, a structural loss function is set, and self-attention is used to retain sample details so that the difference between the self-attention map of the latent vector before perturbation and the latent vector after perturbation at the corresponding number of steps is minimized, which can improve the details of the adversarial sample.
[0081] In this embodiment, a transfer loss function is set, and the prior knowledge of the stable diffusion model is used to use cross attention to distract the attention of the stable diffusion model from the attention range of the text prompt, which can improve the transfer ability of the adversarial sample.
[0082] In this embodiment, a classifier loss function is set, and the mask obtained by text segmentation is used to limit the area where the disturbance is added. This can improve the structural similarity of the adversarial samples and ensure the success rate of the adversarial attack.
[0083] The final objective function is as follows:
[0084]
[0085] where x t represents the potential vector for attack, argmin(·) represents the parameter value when the function reaches the minimum, L represents the objective function, L1 represents the structural loss function, L2 represents the transfer loss function, L3 represents the classifier loss function, a represents the weight of the structural loss function, b represents the weight of the transfer loss function, and c represents the weight of the classifier loss function.
[0086] The formula of the structural loss function is as follows:
[0087] L1=MSE(S t ',S t )
[0088] Where L1 represents the structural loss function, MSE(·) represents the mean square error, S t ' represents the self-attention matrix of the latent vector after perturbation, S t Indicates the corresponding S t 'The unperturbed latent vector self-attention matrix at time steps;
[0089] The formula of the migration loss function is as follows:
[0090]
[0091] Where L2 represents the migration loss function, Var(·) represents the calculation variance, N represents the total number of reverse diffusions, and x t represents the latent vector at the t-th step in reverse diffusion, Cross(·) represents the accumulated cross attention during reverse reconstruction, P represents the textual prompt corresponding to the image, and SDM represents the stable diffusion model;
[0092] The formula of the classifier loss function is as follows:
[0093]
[0094] Where L3 represents the classifier loss function, J(·) represents the cross entropy loss, x represents the original input image, and x′ represents the model after adversarial attack. The generated perturbation image, M represents the target area of the adversarial attack, y represents the label category, and this embodiment uses the classifier to output the category label with the original image as input.
Claims
1. A method for countering attacks based on a diffusion model, characterized in that: The following steps are involved: S1. Obtain text and use a multimodal object detection model to predict the detection box corresponding to the text in the image; S2, use the segmentation model to predict the mask corresponding to the detection box, and integrate the mask set to obtain the target area for the adversarial attack; S3, obtain the image, and use the stable diffusion model to map the image to the latent space corresponding to the image, and save the latent vector of each step; S4. Iterate the adversarial attack and add perturbations to the latent space. Combine the target area and the latent vector, and use the strategy of introducing the diffusion process and area selection into the adversarial attack to generate adversarial samples, completing the adversarial attack based on the diffusion model.
2. The method for countering attacks based on a diffusion model according to claim 1, characterized in that: The S1 comprises the following steps: S101, obtaining an image on which an adversarial attack is to be performed and a text label corresponding to the image; S102: Use a multimodal object detection model to obtain detection boxes corresponding to text labels, and retain detection boxes that are larger than a preset threshold.
3. The method for countering attacks based on a diffusion model according to claim 1, characterized in that: The S2 comprises the following steps: S201, arranging the image and the detection frame obtained in S1, and aligning the position and size of the image and the detection frame; S202, outputting a predicted mask set using a large segmentation model according to the image and detection frame processed in S201; S203: Integrate the mask set into a single mask, and use the single mask as a target area for countermeasure attack.
4. The method for countering attacks based on a diffusion model according to claim 1, characterized in that: The S3 comprises the following steps: S301, pre-training a stable diffusion model; S302, acquiring an image, and using an encoder of a pre-trained stable diffusion model to map the image to a latent space corresponding to the image, perform forward diffusion and noise processing, and retain each intermediate latent vector.
5. The method for countering attacks based on a diffusion model according to claim 4, characterized in that: The formula for forward diffusion noise addition is as follows: in, It is parameterized as The deterministic inverse sampling process, x t represents the potential vector of time step t, and x0 represents the potential vector of the original image output by the encoder.
6. The method for countering attacks based on a diffusion model according to claim 1, characterized in that: The S4 comprises the following steps: S401, iterative adversarial attack, and adding disturbances to the latent space during the reverse diffusion denoising process; S402, setting a structural loss function; S403, setting a migration loss function; S404, setting a classifier loss function; S405. Construct an objective function, use the weights of the structural loss function, the weights of the transfer loss function, and the weights of the classifier loss function, jointly optimize the structural loss function, the transfer loss function, and the classifier loss function, use the decoder of the pre-trained stable diffusion model to decode the latent vector obtained by the objective function to generate an adversarial sample, and complete the adversarial attack based on the diffusion model.
7. The method for countering attacks based on a diffusion model according to claim 6, characterized in that: The structural loss function formula is as follows: L1=MSE(S′ t ,S t ) Among them, L1 represents the structural loss function, MSE(·) represents the mean square error, and S′ t represents the self-attention matrix of the latent vector after perturbation, S t Indicates the corresponding S t 'The unperturbed latent vector self-attention matrix at time steps; The migration loss function formula is as follows: Where L2 represents the migration loss function, Var(·) represents the calculation variance, N represents the total number of reverse diffusions, and x t represents the latent vector at the t-th step in reverse diffusion, Cross(·) represents the accumulated cross attention during reverse reconstruction, P represents the textual prompt corresponding to the image, and SDM represents the stable diffusion model; The formula of the classifier loss function is as follows: Among them, L3 represents the classifier loss function, J(·) represents the cross entropy loss, x represents the original input image, and x′ represents the model after the adversarial attack. The generated perturbation image, M represents the target area of the adversarial attack, and y represents the label category; The objective function formula is as follows: Among them, x t represents the potential vector for attack, argmin(·) represents the parameter value when the function reaches the minimum, L represents the objective function, L1 represents the structural loss function, L2 represents the transfer loss function, L3 represents the classifier loss function, a represents the weight of the structural loss function, b represents the weight of the transfer loss function, and c represents the weight of the classifier loss function.
Citation Information
Cited By
CPE recognition attack-resisting defense method and system based on Diffusion security large model
CN120316782A
A CPE identification and counter-attack defense method and system based on Diffusion security model
CN120316782B
Multi-target countermeasure attack method and device based on text description
CN120510487A
Active defense method for deep counterfeiting of human face based on stable diffusion model
CN120726705A
