Confrontation sample detection device and method aiming at black box query attack
Through the feature extraction and similarity calculation of the adversarial sample detection device, black box query attacks are identified and defended, which solves the problem of insufficient robustness of the deep learning model under black box attacks and achieves efficient and accurate attack identification and defense.
Patent Information
- Application Number
- CN202410626601.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-08-27
AI Technical Summary
Deep learning models lack effective defense methods in the face of black-box query attacks, which limits their application in real environments.
An adversarial sample detection device is used, and through the feature extraction module, similarity calculation module and judgment module, the trained feature extractor and prompts are used to perform feature extraction and similarity calculation on the input image to determine whether it is a black box query attack. and adopt a defensive strategy.
It can efficiently and accurately identify black box query attacks, reduce the attack success rate, and show the best performance in a variety of attack scenarios.
Smart Images

Figure CN118551202A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence security, and specifically relates to an adversarial sample detection device and method for black-box query attacks. Background Art
[0002] In recent years, deep learning technology has made remarkable progress in a variety of tasks and practical application scenarios, such as computer vision, natural language processing, and multimodal learning. Despite these research advances, many studies have found that deep learning models have adversarial robustness defects. Deep vision models that perform well in normal environments can easily be deceived by adversarial samples maliciously constructed by attackers. This lack of robustness seriously limits the application of deep vision models in real environments. Given the potential threats that adversarial robustness defects pose to deep learning models and their applications, resisting potential adversarial attacks has become an urgent problem to be solved.
[0003] Generally speaking, adversarial attacks can be divided into white-box attacks and black-box attacks, depending on the different prior information that the attacker can obtain. White-box attacks assume that the attacker can obtain all the information of the target model, including training data, hyperparameters, activation functions, model architecture and parameters, etc. At present, most research on adversarial attacks focuses on white-box attacks, such as FGSM, BIM, PGD, and C&W. Black-box attacks assume that the attacker cannot obtain relevant information of the target model, but can only obtain the output information of the target model, that is, logical values or probabilities. Therefore, adversarial samples are generated through approximate gradients. Depending on the approximate gradient method, black-box attacks can be divided into migration attacks and query attacks. Compared with white-box attacks, black-box attacks are more in line with actual application scenarios and more challenging.
[0004] Therefore, how to improve the ability to defend against black box attacks is an urgent problem to be solved in the field of model security. Summary of the invention
[0005] The present invention is made to solve the above-mentioned problem, and its purpose is to provide an adversarial sample detection device and method for black-box query attacks.
[0006] The present invention provides an adversarial sample detection device for black-box query attacks, which is used to analyze whether a query image input into a deep learning module is a black-box query attack, and has the following characteristics, including: a feature extraction module, which includes a trained feature extractor and a trained prompt, and is used to extract features from the query image to obtain a corresponding feature vector as a current feature vector; a feature storage module, which is used to store feature vectors; a similarity calculation module, which is used to perform similarity calculations on the current feature vector and multiple historical feature vectors respectively to obtain corresponding similarity scores; a judgment module, which includes a preset similarity threshold, and is used to judge whether any similarity score is greater than the similarity threshold, if so, the query image is a black-box query attack, if not, the query image is not a black-box query attack, wherein the historical feature vector is a feature vector stored in the feature storage module before the current feature vector.
[0007] The adversarial sample detection device for black-box query attack provided by the present invention may also have the following features: wherein, the feature extractor and the trainable prompt are trained by multiple existing query images to obtain the trained feature extractor and the trained prompt, specifically including the following steps: Step S1, performing two random data enhancements on each existing query image to obtain the corresponding first enhanced image and the second enhanced image Step S2: for each existing query image, the corresponding first enhanced image and the second enhanced image Carry out adversarial attacks respectively to obtain the corresponding first enhanced image The third enhanced image and the corresponding second enhanced image The fourth enhanced image Step S3: for each existing query image, the corresponding first enhanced image Second enhanced image The third enhanced image and the fourth enhanced image as a training image group; step S4, according to the training image group corresponding to all existing query images, and in combination with the loss function, fine-tune the feature extractor and the trainable prompt to obtain a trained feature extractor and a trained prompt.
[0008] In the adversarial sample detection device for black-box query attack provided by the present invention, it can also have the following characteristics: wherein the expression of the loss function is: where p is the trainable hint, E(·) is the feature extractor, sim(·,·) is the cosine similarity function, τ is the temperature, α is a hyperparameter, and N is the size of each batch of data input during training.
[0009] The adversarial sample detection device for black-box query attacks provided by the present invention may also have the following feature: wherein α=0.5.
[0010] The adversarial sample detection device for black-box query attacks provided by the present invention may also have the following feature: wherein, in step S2, the adversarial attack is a PGD adversarial attack.
[0011] The adversarial sample detection device for black-box query attacks provided by the present invention may also have the following feature: wherein the feature extractor is an image encoder of the CLIP model.
[0012] In the adversarial sample detection device for black-box query attacks provided by the present invention, it can also have the following characteristics: wherein, the feature vector in the feature storage module is float16 precision, and the similarity calculation module and the feature extraction module both use the PyTorch automatic mixed precision method to determine the appropriate precision for each operation, and the appropriate precision is single precision or half precision.
[0013] In the adversarial sample detection device for black-box query attacks provided by the present invention, it may also have such features, and also include: a defense operation module, which is used to perform corresponding defense operations when the query image is a black-box query attack, wherein the defense operations include: rejecting queries; limiting the number and frequency of queries of the user corresponding to the query image; returning deliberately disturbed output to the user; prohibiting the account corresponding to the user or blocking the IP address corresponding to the user; returning historical outputs corresponding to queries similar to the query image to the user.
[0014] The present invention also provides an adversarial sample detection method for black-box query attacks, which is used to analyze whether a query image input into a deep learning module is a black-box query attack, and has such characteristics, comprising the following steps: step T1, extracting features from the query image according to a trained feature extractor and a trained prompt, and obtaining a corresponding feature vector as a current feature vector; step T2, storing the current feature vector; step T3, calculating the similarity between the current feature vector and multiple historical feature vectors, and obtaining corresponding similarity scores; step T4, judging whether any similarity score is greater than a similarity threshold, if so, the query image is a black-box query attack, if not, the query image is not a black-box query attack, wherein the historical feature vector is a feature vector stored before the current feature vector.
[0015] Functions and Effects of the Invention
[0016] According to the adversarial sample detection device and method for black-box query attacks involved in the present invention, because the feature extractor can be fine-tuned by adversarial contrast prompts, the feature extractor can be trained by training prompts and loss functions, thereby obtaining a trained feature extractor, and then the feature vector extracted by the feature extractor is used to determine whether the corresponding image is a black-box query attack through the similarity score between the current feature vector and the historical feature vector, and adopt a corresponding defense strategy. Therefore, the adversarial sample detection device and method for black-box query attacks of the present invention can efficiently and accurately identify black-box query attacks. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 Schematic diagram of the working principle of the adversarial sample detection device for black-box query attack in an embodiment of the present invention;
[0018] Figure 2 is a block diagram of an adversarial sample detection device in an embodiment of the present invention;
[0019] Figure 3 is a flow chart of training a feature extractor and prompting in an embodiment of the present invention;
[0020] Figure 4 is a schematic diagram of the training principle of a feature extractor in an embodiment of the present invention;
[0021] Figure 5 It is a flowchart of an adversarial sample detection method for black-box query attacks in an embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the following embodiments and the accompanying drawings specifically illustrate the adversarial sample detection device and method for black-box query attacks of the present invention.
[0023] In this embodiment, an adversarial sample detection device for black-box query attacks is provided, which is used to analyze whether a query image input into a deep learning module is a black-box query attack.
[0024] Figure 1 It is a schematic diagram of the working principle of the adversarial sample detection device for black-box query attacks in an embodiment of the present invention.
[0025] like Figure 1 As shown, the adversarial sample detection device extracts feature vectors from images input by each user, i.e., a normal user or an attacker, through a CLIP image encoder and prompts, and calculates the extracted feature vector, i.e., the current feature vector, with the stored historical feature vector to obtain the current query similarity, thereby determining whether the user corresponding to the image is a normal user or an attacker, and executing a defense strategy against the attacker, thereby achieving defense against black-box query attacks.
[0026] Figure 2 is a block diagram of an adversarial sample detection device in an embodiment of the present invention.
[0027] like Figure 2 As shown, the adversarial sample detection device 100 includes a feature extraction module 10 , a feature storage module 20 , a similarity calculation module 30 , a judgment module 40 and a defense operation module 50 .
[0028] The feature extraction module 10 includes a trained feature extractor and a trained prompt, and is used to extract features from the query image and obtain a corresponding feature vector as the current feature vector. The feature extractor is an image encoder of the CLIP model.
[0029] Figure 3 It is a flowchart of training a feature extractor and prompts in an embodiment of the present invention.
[0030] Figure 4 Schematic diagram of the training principle of the feature extractor in an embodiment of the present invention.
[0031] like Figure 3 , Figure 4 As shown, training a feature extractor and a trainable prompt by using multiple existing query images to obtain a trained feature extractor and a trained prompt includes the following steps:
[0032] Step S1: Perform two random data enhancements on each existing query image x to obtain the corresponding first enhanced image and the second enhanced image
[0033] Step S2: for each existing query image, the corresponding first enhanced image and the second enhanced image Carry out adversarial attacks respectively to obtain the corresponding first enhanced image The third enhanced image and the corresponding second enhanced image The fourth enhanced image
[0034] Among them, the adversarial attack is the PGD adversarial attack.
[0035] Step S3: for each existing query image, the corresponding first enhanced image Second enhanced image The third enhanced image and the fourth enhanced image as a training image set.
[0036] Step S4, according to the training image group corresponding to all existing query images and in combination with the loss function, fine-tune the feature extractor and the trainable prompt to obtain a trained feature extractor and a trained prompt.
[0037] Among them, the expression of the loss function is:
[0038]
[0039]
[0040]
[0041] Where p is the trainable hint, E(·) is the feature extractor, sim(·,·) is the cosine similarity function, τ is the temperature, α is the hyperparameter, and N is the size of each batch of data input during training. In this embodiment, α=0.5.
[0042] In this embodiment, the loss and loss Two types of losses are used to efficiently fine-tune the feature extractor: on the one hand, the contrastive loss learns a robust feature representation for the clean image, i.e., the existing query image, and its samples after data augmentation, i.e., the first augmented image and the second augmented image, and the adversarial samples, i.e., the third augmented image and the fourth augmented image; on the other hand, the adversarial loss is used to make it robust to adaptive attacks.
[0043] The feature storage module 20 is used to store feature vectors.
[0044] Among them, the feature vector in the feature storage module 20 is float16 precision, and the similarity calculation module and the feature extraction module both adopt the PyTorch automatic mixed precision method, so as to automatically convert between half-precision and single-precision floating point numbers and determine the appropriate precision for each operation, which is single precision or half precision.
[0045] In this embodiment, the use of float16 precision can reduce the storage cost of the feature storage module 20. For example, each query generates a vector embedding of dimension , which requires 2048 bytes for float32 precision. When 1 million users query 100 times each, the storage space required to store all these query embeddings is about 190.73GB, and by switching to float16 precision, the storage space can be reduced to about 95.37GB, which can obviously greatly reduce the storage cost.
[0046] The similarity calculation module 30 is used to calculate the similarity between the current feature vector and multiple historical feature vectors respectively to obtain corresponding similarity scores. In this embodiment, the similarity calculation module 30 uses all historical feature vectors stored in the feature storage module 20 to perform similarity calculation.
[0047] The historical feature vector is a feature vector stored in the feature storage module 20 before the current feature vector.
[0048] This embodiment targets the inherent weakness of black-box query attacks, that is, it is necessary to generate similar samples, i.e., adversarial samples, during the attack process to query the victim model multiple times, thereby calculating similarity scores to query whether there are historical feature vectors that are extremely similar to the current feature vector from a large number of historical feature vectors. If there are extremely similar historical feature vectors, it indicates that the image corresponding to the current feature vector is the same as the image corresponding to the historical feature vector. In view of the fact that the images normally input by the user are all different, the image corresponding to the current feature vector is determined to be a black-box query attack.
[0049] The judgment module 40 includes a preset similarity threshold, which is used to judge whether any similarity score is greater than the similarity threshold. If so, the query image is a black box query attack, and if not, the query image is not a black box query attack. In this embodiment, the threshold range of the similarity threshold is 0.9 to 0.95.
[0050] The defense operation module 50 is used to perform corresponding defense operations when the query image is a black box query attack.
[0051] Among them, the defense operations include: rejecting queries; limiting the number and frequency of queries of the user corresponding to the query image; returning deliberately disturbed output to the user; prohibiting the account corresponding to the user or blocking the IP address corresponding to the user; returning historical output corresponding to queries similar to the query image to the user.
[0052] The following describes the process of using the adversarial sample detection device 100 to perform an adversarial sample detection method for black-box query attacks in conjunction with the accompanying drawings.
[0053] Figure 5 It is a flowchart of an adversarial sample detection method for black-box query attacks in an embodiment of the present invention.
[0054] like Figure 5 As shown in FIG. 1 , the adversarial sample detection method for black-box query attack includes the following steps:
[0055] Step T1, using the feature extraction module 10 to extract features from the query image according to the trained feature extractor and the trained prompt, and obtaining a corresponding feature vector as the current feature vector.
[0056] Step T2: using the feature storage module 20 to store the current feature vector.
[0057] Step T3: Use the similarity calculation module 30 to calculate the similarity between the current feature vector and multiple historical feature vectors respectively to obtain corresponding similarity scores.
[0058] Step T4, using the judgment module 40 to judge whether any similarity score is greater than the similarity threshold, if so, the query image is a black box query attack, if not, the query image is not a black box query attack.
[0059] In this embodiment, the existing CIFAR-10 dataset and ImageNet dataset are respectively used to perform black-box query attack defense and no defense on the adversarial sample detection method for black-box query attack using the ACPT method of this embodiment. In the face of multiple different attack methods, including the Boundary attack method, the HSJA attack method, the NESS attack method, the QEBA attack method, the Square attack method and the ZOO attack method, the corresponding attack success rate and related data are shown in the following table:
[0060]
[0061]
[0062] In the above table, the first column is each data set, the second column is each attack method, the third and fourth columns are the attack success rate and query number without defense, and the fifth to eighth columns are the attack success rate, the probability of successfully identifying the black box query attack within 3 black box query attacks, i.e., the 3 detection success rate, the probability of successfully identifying the black box query attack within 5 black box query attacks, i.e., the 5 detection success rate, and the average number of detections required for successful identification, i.e., the average number of detections. It can be seen that although most attacks can achieve a high attack success rate, i.e., close to 100%, without defense measures, they usually require a large number of queries to succeed. Correspondingly, the ACPT method reduces the attack success rate to 0%, the detection success rate is as high as 97% / 99% within 3 / 5 times, and only 2.66 detections are required on average to successfully defend against query attacks. In addition, the ACPT method exhibits the best performance and a 3 / 5 detection success rate of almost 100% in most scenarios.
[0063] Functions and Effects of the Embodiments
[0064] According to the adversarial sample detection device and method for black-box query attacks involved in this embodiment, the feature extractor can be fine-tuned by adversarial comparison prompts, and the feature extractor can be trained by training prompts and loss functions to obtain a trained feature extractor, and then the feature vector extracted by the feature extractor is used to determine whether the corresponding image is a black-box query attack through the similarity score between the current feature vector and the historical feature vector, and a corresponding defense strategy is adopted. In short, this method can efficiently and accurately identify black-box query attacks.
[0065] Those skilled in the art should understand that the present invention is not limited to the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. An adversarial sample detection device for black-box query attacks, used to analyze whether a query image input into a deep learning module is a black-box query attack. It is characterized in that include: A feature extraction module, comprising a trained feature extractor and a trained prompt, for extracting features from the query image to obtain a corresponding feature vector as a current feature vector; A feature storage module, used for storing the feature vector; A similarity calculation module is used to calculate the similarity between the current feature vector and multiple historical feature vectors respectively to obtain corresponding similarity scores; A judgment module includes a preset similarity threshold, which is used to judge whether any of the similarity scores is greater than the similarity threshold. If so, the query image is a black box query attack; if not, the query image is not a black box query attack. The historical feature vector is the feature vector stored in the feature storage module before the current feature vector.
2. The adversarial sample detection device for black box query attack according to claim 1 , Features: in, Training the feature extractor and the trainable prompts by using a plurality of existing query images to obtain the trained feature extractor and the trained prompts specifically includes the following steps: Step S1: Perform two random data enhancements on each of the existing query images to obtain a corresponding first enhanced image. and the second enhanced image Step S2: for each of the existing query images, the corresponding first enhanced image and the second enhanced image Carry out adversarial attacks respectively to obtain the corresponding first enhanced image The third enhanced image and the corresponding second enhanced image The fourth enhanced image Step S3: for each existing query image, the corresponding first enhanced image The second enhanced image The third enhanced image and the fourth enhanced image As a training image set; Step S4, according to the training image group corresponding to all the existing query images and in combination with the loss function, fine-tune the feature extractor and the trainable prompt to obtain the trained feature extractor and the trained prompt.
3. The adversarial sample detection device for black-box query attack according to claim 2, characterized in that: in, The expression of the loss function is: Where p is the trainable cue, E(·) is the feature extractor, sim(·,·) is the cosine similarity function, τ is the temperature, α is a hyperparameter, and N is the size of each batch of data input during training.
4. The adversarial sample detection device for black-box query attack according to claim 3, characterized in that: in, α=0.5。 5. The adversarial sample detection device for black-box query attack according to claim 2, characterized in that: in, In step S2, the adversarial attack is a PGD adversarial attack.
6. The adversarial sample detection device for black-box query attack according to claim 2, characterized in that: in, The feature extractor is an image encoder of the CLIP model.
7. The adversarial sample detection device for black-box query attack according to claim 1, characterized in that: in, The feature vector in the feature storage module has float16 precision. The similarity calculation module and the feature extraction module both use the PyTorch automatic mixed precision method to determine the appropriate precision for each operation. The appropriate precision is single precision or half precision.
8. The adversarial sample detection device for black-box query attack according to claim 1, It is characterized in that Also includes: A defense operation module is used to perform corresponding defense operations when the query image is the black box query attack. The defense operation includes: Refusal of enquiry; Limit the number and frequency of queries by users corresponding to the query image; returning an intentionally perturbed output to the user; Ban the account corresponding to the user or block the IP address corresponding to the user; Return historical outputs corresponding to queries similar to the query image to the user.
9. A method for detecting adversarial samples against black-box query attacks, used to analyze whether a query image input into a deep learning module is a black-box query attack. It is characterized in that The following steps are involved: Step T1, extracting features from the query image according to the trained feature extractor and the trained prompt, and obtaining a corresponding feature vector as the current feature vector; Step T2, storing the current feature vector; Step T3, calculating similarity between the current feature vector and multiple historical feature vectors respectively to obtain corresponding similarity scores; Step T4, determining whether any of the similarity scores is greater than a similarity threshold, if so, the query image is a black box query attack, if not, the query image is not a black box query attack, The historical feature vector is the feature vector stored before the current feature vector.
Citation Information
Patent Citations
Black box attack confrontation sample generation method and system
CN113704758A
Black-box adversarial attacks on videos
US10783401B1
