Method for preparing confrontation sample based on universal potential infection
By constructing an adversarial sample generation model of feature extractor, size matching module and generator, the problem that the existing technology cannot generate adversarial samples of unknown target categories is solved, and the universality and quality improvement of adversarial sample generation is achieved, which is suitable for a variety of applications. Application scenario.
Patent Information
- Application Number
- CN202411105388.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-08-13
AI Technical Summary
Existing adversarial sample generation methods cannot effectively generate adversarial samples for unknown target categories, limiting the comprehensiveness of vulnerability assessment of deep neural networks (DNNs).
Adopting an adversarial sample preparation method based on common potential infections, by obtaining a clean sample set and a target sample set, dividing known and unknown categories, building an adversarial sample generation model including feature extractor, size matching module and generator, and training the model to generate Adversarial samples, supporting the generation of any target samples.
It improves the versatility and quality of adversarial sample generation, can introduce category features between different class images, effectively generate high-quality adversarial samples, and has a wide range of application scenarios for unknown target categories.
Smart Images

Figure CN119068286A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of adversarial sample generation, and more specifically, relates to a method for preparing adversarial samples based on universal potential infection. Background Art
[0002] Deep neural networks (DNNs) have made remarkable progress in the field of artificial intelligence and have been successfully applied to many fields such as image recognition, natural language processing, and autonomous driving. Despite their great success, DNNs have been shown to be very vulnerable to adversarial attacks, which mislead DNNs by adding perturbations that are almost imperceptible to the human eye to clean images. Therefore, it is crucial to understand the mechanisms behind DNNs and design effective evaluation methods to identify the flaws of DNNs before they are deployed in safety-sensitive applications.
[0003] Adversarial attacks can generally be divided into two categories: untargeted attacks and targeted attacks. Untargeted attacks aim to make DNNs fail, while targeted attacks not only make DNNs fail but also mislead them to recognize images as preset specific targets. Targeted attacks have become the main tool for DNNs vulnerability assessment due to their high flexibility and serious threat to security-sensitive applications.
[0004] Targeted attack methods are mainly divided into two technical routes: iterative framework and generator-based framework. The iterative framework generates adversarial samples for each clean image in an iterative manner, but it is easy to overfit the white-box model and has high computational overhead. The generator-based framework, on the other hand, constructs adversarial samples by using a well-trained generative model, showing good transfer potential. However, the generators used in existing methods are only trained to adapt to known target categories. For unknown target categories (i.e., categories not seen during training), existing methods cannot generate effective adversarial samples unless the generator is retrained, which limits the comprehensive evaluation of DNNs. Summary of the invention
[0005] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a method for preparing adversarial samples based on universal potential infection. The constructed adversarial sample generation model supports the generation of adversarial samples based on any target sample, regardless of whether the target sample is a known category, thereby improving the universality of adversarial sample generation.
[0006] In order to achieve the above-mentioned object of the invention, the method for preparing a universal potential infection-based anti-sample comprises the following steps:
[0007] S1: According to actual needs, two image sample sets are obtained, namely the clean sample set C and the target sample set T. The clean sample set contains several clean samples x c , the target sample set contains several target samples x t, label each image sample with its corresponding category;
[0008] S2: Classify the sample categories in the target sample set into known category sets y according to actual needs known and the unknown category set y unknown ;
[0009] S3: The categories in the target sample set T belong to the known category set y known The target samples constitute the target sample set R; for each clean sample x in the clean sample set C c , randomly select a sample from the target sample set R that matches the clean sample x c Target samples x of different categories t , the clean sample x c and the target sample x t As training sample pairs, thus forming a training sample set;
[0010] S4: Construct an adversarial sample generation model, including a feature extractor, a size matching module, and a generator, where:
[0011] The feature extractor is used to extract features from the target sample and send the obtained target feature image to the size matching module;
[0012] The size matching module is used to map the target feature images to the input image sizes of the K infection layers of the generator, and send the target feature images of K different sizes to the corresponding infection layers of the generator;
[0013] The generator is used to generate adversarial samples x based on the input clean samples and K target feature images of different sizes. adv , wherein K layers are pre-selected as infection layers in each structural layer of the generator, and during the generation process, the original input features of each infection layer are superimposed with the received target feature image and then input into the infection layer for processing;
[0014] S5: Use the training sample set to train the adversarial sample generation model to obtain a trained adversarial sample generation model;
[0015] S6: For each clean sample x in the clean sample set C c , arbitrarily select a target sample with a different category from the target sample set T, and then input them into the adversarial sample generation model trained in step S5 to obtain an adversarial sample.
[0016] The present invention is based on a method for preparing adversarial samples of general potential infection. First, a clean sample set and a target sample set are obtained, and the categories contained in the target sample set are divided into known categories and unknown categories. The target samples in the target sample set whose categories belong to the known category set constitute the target sample set, and an adversarial sample generation model including a feature extractor, a size matching module and a generator is constructed. The model extracts features from the target samples, performs size matching, and then superimposes them on the infection layer input corresponding to the generator, thereby infecting the clean samples to generate adversarial samples; the training sample set is used to train the adversarial sample generation model, and then for each clean sample in the clean sample set, any target sample with a different category from the target sample set is selected and input into the trained adversarial sample generation model together to obtain the adversarial sample.
[0017] The present invention has the following beneficial effects:
[0018] 1) The present invention can introduce category features between images of different categories without relying on a specific category or target DNN model, thereby improving the generation capability and quality of adversarial samples for unknown target categories;
[0019] 2) Experiments have shown that the present invention can be used for standard models, adversarial training models and vision-language based models, and can effectively generate high-quality adversarial samples of any target category, and has a wide range of application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a flowchart of a specific implementation method of the method for preparing a universal potential infection-based anti-sample of the present invention;
[0021] Figure 2 It is a structural diagram of the adversarial sample generation model in the present invention;
[0022] Figure 3 Schematic diagram of training and attacking the adversarial sample generation model in this embodiment;
[0023] Figure 4 is a comparison chart of the attack success rates of the present invention in this embodiment in a series of known categories;
[0024] Figure 5 is a comparison chart of the attack success rates of the method of the present invention and the random selection method for known categories in this embodiment;
[0025] Figure 6 is a comparison chart of the number of samples in each category and the attack success rate of attacking unknown categories in this embodiment. DETAILED DESCRIPTION
[0026] The specific implementation of the present invention is described below in conjunction with the accompanying drawings so that those skilled in the art can better understand the present invention. It should be noted that in the following description, when the detailed description of known functions and designs may dilute the main content of the present invention, these descriptions will be omitted here.
[0027] Example
[0028] Figure 1 FIG. 1 is a flow chart of a specific implementation method of the method for preparing a universal potential infection-based anti-sample according to the present invention. Figure 1 As shown, the specific steps of the method for preparing a universal potential infection-resistant sample according to the present invention are as follows:
[0029] S101: Obtain image sample set:
[0030] According to actual needs, two image sample sets are obtained, namely the clean sample set C and the target sample set T. The clean sample set contains several clean samples x c , the target sample set contains several target samples x t , label each image sample with its corresponding category.
[0031] S102: Classification type:
[0032] According to actual needs, the sample categories in the target sample set are divided into known category sets y known and the unknown category set y unknown .
[0033] S103: Select a training sample set:
[0034] The categories in the target sample set T belong to the known category set y known The target samples constitute the target sample set R. For each clean sample x in the clean sample set C c , randomly select a sample from the target sample set R that matches the clean sample x c Target samples x of different categories t , the clean sample x c and the target sample x t As training sample pairs, thus forming a training sample set.
[0035] S104: Constructing adversarial sample generation model:
[0036] In order to generate high-quality adversarial samples, the present invention constructs an adversarial sample generation model. Figure 2 It is a structural diagram of the adversarial sample generation model in the present invention. Figure 2As shown, the adversarial sample generation model in the present invention includes a feature extractor, a dimension matching module (DMM) and a generator. Next, each module is described in detail.
[0037] The feature extractor is used to extract features from the target sample and send the obtained target feature image to the size matching module. In this embodiment, the feature extractor uses a feature extraction module that removes the classification head module from the pre-trained classification model, so that the feature extractor parameters can be fixed during training to improve training efficiency.
[0038] The size matching module is used to map the target feature images to the input image sizes of the K infection layers of the generator, and send the K target feature images of different sizes to the corresponding infection layers of the generator. The size matching module is a commonly used module in the field of computer vision or deep learning. In practical applications, the specific structure can be set as needed.
[0039] The generator is used to generate adversarial samples x based on the input clean samples and K target feature images of different sizes. adv , wherein K layers are pre-selected as infection layers in each structural layer of the generator, and the original input features of each infection layer are superimposed with the received target feature image and then input into the infection layer for processing. Using the above method, the features of the target sample can be introduced to infect the clean sample, thereby generating an adversarial sample. The generator of this embodiment adopts a U-Net network, which consists of a series of convolutional layers and pooling operations, including a symmetrical encoder (downsampling path) and a decoder (upsampling path). U-Net has skip connections, which can help convey richer information and alleviate the problem of gradient disappearance, thereby improving the quality of the generated image. In practical applications, the initial image output by the generator may exceed the pixel value, so the clipping function clip() is used for processing to clip the value to the image pixel value range, thereby obtaining an adversarial sample.
[0040] S105: Training adversarial sample generation model:
[0041] The training sample set is used to train the adversarial sample generation model to obtain a trained adversarial sample generation model.
[0042] The setting of the loss function is very important for adversarial sample generation models and can be set as needed in practical applications. Figure 3 Schematic diagram of training and attacking the adversarial sample generation model in this embodiment. Figure 3As shown, the loss function of the adversarial sample generation model in this embodiment adopts two parts, one is the feature similarity between the target sample and the generated adversarial sample, and the other is the feature similarity between the clean sample and the difference noise of the generated adversarial sample and the target sample. The specific calculation method of the loss function LOSS is as follows:
[0043] LOSS = [1-S(F(x adv ),F(x t ))]+α[1-S(F(δ),F(x t ))]
[0044] Among them, S() represents the feature similarity, F() represents feature extraction, δ = x adv -x c represents the deviation image, and α represents the weight hyperparameter. In this embodiment, the feature extraction module of the classification head module is removed from the pre-trained classifier for feature extraction, and the feature similarity adopts the cosine distance.
[0045] S106: Generate adversarial samples:
[0046] For each clean sample x in the clean sample set C c , arbitrarily select a target sample with a different category from the target sample set T, and then input them together into the adversarial sample generation model trained in step S105 to obtain an adversarial sample.
[0047] In order to better illustrate the technical effect of the present invention, a specific example is used to experimentally verify the present invention.
[0048] Example
[0049] This embodiment is intended to demonstrate the effectiveness of the present invention. In this embodiment, the model of the present invention is trained using the ImageNet training set, and the performance is evaluated on the ImageNet validation set. The present invention considers a variety of network models, including DenseNet-121, ResNet-50, and VGG-19 as alternative models. In this embodiment, a variety of black box models are selected, including ResNet-152, VGG-19, Inception-v3, ViT, DeiT, and CLIP, to test the transferability of the attack. Then, the present invention evaluates the proposed method on the defense model. The defense models selected in this embodiment include Inc-v3adv, Inc-v3ens3, Inc-v3ens4, IncRes-v2ens, and large visual-language models such as LLaVA and Qwen-VL.
[0050] For different attack categories, different comparison methods are selected in this embodiment: for iterative attacks, MI algorithm and SU algorithm are selected; for single target generation attack, TTP method is selected; for multi-target generation attack, HGN and ESMA are selected. In all experiments, the perturbation constraint ε is set to 16, the number of known categories N is set to 200, α is set to 0.5, and the number of samples M in each known category is set to 325. The present invention uses the AdamW optimizer to train the generator for 20 cycles.
[0051] In this embodiment, 200 categories are selected from ImageNet as known categories, and the remaining 800 categories are used as unknown categories. Then the generator is trained using the known categories, and the success rate of the targeted attack is evaluated on the unknown categories. Since only HGN and the method of the present invention can be evaluated on unknown categories, this embodiment only compares the attack success rates of the present invention (denoted as GAKEr) and HGN on different models. Table 1 is a comparison table of the attack success rates of the present invention and the HGN algorithm in this embodiment.
[0052]
[0053] Table 1
[0054] As shown in Table 1, the attack success rate of the present invention is significantly better than that of HGN, highlighting its excellent transferability. For example, when using ResNet-50 as a substitute model and VGG-19 as a black-box model, the present invention achieved a success rate of 41.69% on unknown categories, while HGN only achieved 0.05%. This result highlights the limitations of existing methods in generating targeted adversarial samples for unknown categories, while the present invention demonstrates effective generalization capabilities for these categories. Even when the substitute model is ResNet-50, the attack success rate of the present invention on unknown categories on the VGG-19 black-box model reached 41.69%, which highlights the limitations of existing methods in generating adversarial samples for unknown categories, while demonstrating the effective generalization capabilities of the present invention on these categories.
[0055] In addition, the method of the present invention is compared with the most advanced iteration-based method (SU), single target generator-based attack (TTP) and multi-target generator-based attack (HGN, ESMA) in the evaluation of known categories. All attacks based on multi-target generators (HGN, ESMA and the method of the present invention) are trained in the same 200 categories. The same 200 categories are trained. Since the TTP method needs to train a model for each target category, the cost of training 200 models is too high. Therefore, 10 categories are randomly selected from the 200 categories, and 10 TTP models (TTP-10) are trained for each alternative model. Then, the method of the present invention (denoted as GAKEr-10) is tested on the same 10 categories. Table 2 is a comparison table of the success rate of directional attacks on known categories by the present invention and the comparative method in this embodiment.
[0056]
[0057] Table 2
[0058] As shown in Table 2, compared with the iteration-based SU method, the proposed method has a higher success rate in targeted attacks on black-box models. For example, if the alternative model is Dense-121, the average success rate of the proposed method on different models is 10.38% higher than that of SU. Among different models, the proposed method is 10.38% higher than SU on average. For generator-based attacks, the attack success rate of the proposed method is similar to that of the ESMA method, but better than the HGN method. The performance of the proposed method on multiple models is improved by an average of 10.5% and 5.47% over HGN and ESMA, respectively.
[0059] This example also explores the impact of different parameter selections in the training dataset on the generator's attack capabilities. Experimental results show that when the number of selected known categories increases from 10 to 500, the generator's attack success rate on unknown categories significantly improves. In addition, the number of samples selected for each known category has an important impact on the success rate of attacking unknown categories. When the number of samples per category is set to 325, the generator's attack success rate on the white-box model reaches a maximum value of 41.69%.
[0060] Figure 4 : is a comparison chart of the attack success rate of the present invention in a series of known categories in this embodiment. Figure 4As shown in the figure, this embodiment uses Res-50 as an alternative model and includes the performance of the Res-152 black box mode, including the performance of black box models such as Res-152, VGG-19 and Dense-121. The performance is evaluated for known (K) and unknown (U) categories and the impact of the number of known classes N on the performance of the generator is analyzed. When N is limited, such as 10 or 50, the success rate of the generator attacking unknown classes is relatively low. The reason for this limitation is that the generator is trained on a narrow set of known classes, so it is challenging to generalize to a wider range of classes. However, when N is increased to 500, the white box success rate of the generator on the remaining 500 unknown classes is close to 49.45%. Due to parameter and training limitations, it is challenging to expect the generator to continue to obtain a high success rate in a wide range of known categories. Therefore, considering the compromise, the present invention ultimately chooses to set N to 200 to balance the performance of the generator on known and unknown categories.
[0061] According to the description of the present invention, the adversarial sample generation model constructed by the present invention can generate adversarial samples of multiple different target samples, which belongs to a multi-target generation model. Research on multi-target generation models emphasizes that it is necessary not only to determine the number of target categories, but also to select which target categories to attack. When there are obvious differences between the selected target categories, the generator can achieve a higher success rate of targeted attacks.
[0062] The present invention uses similarity to measure the differences between the selected target categories, thereby training the adversarial sample generation model, which mainly includes:
[0063] (1) Select some images with the smallest classification loss for each category.
[0064] (2) Extract the feature vectors of these images and calculate the average value of the feature vectors to represent the target category.
[0065] (3) A similarity greedy algorithm is introduced to select a set of feature vectors with the largest cosine similarity difference to identify known categories.
[0066] Specifically, the algorithm randomly selects a feature vector as the initial category and puts it into the selected group. Then, the algorithm selects a vector from the remaining feature vectors that has the lowest average cosine similarity with the vectors in the selected category group, and adds this selected category to the selected and repeats this process until the specified target number of categories is reached.
[0067] In the present invention, multiple experiments were conducted to eliminate the randomness brought by the initial selection. The effectiveness of the selection method of the present invention was verified and compared with the random selection strategy. Figure 5: is a comparison chart of the attack success rates of the method of the present invention and the random selection method for known categories in this embodiment. Figure 5 As shown in the figure, the method of the present invention is significantly better than random selection on known categories. Compared with the random selection method, the success rate of the present invention on the black box model Res-152 is increased by 16.52%. When the alternative model is Res-50, the success rate of the present invention on the black box model Res-152 is increased by 16.52%. This shows that this proves the necessity of selecting known categories and the effectiveness of the selection method.
[0068] The number of samples in each known category (denoted by M) is a key factor when organizing the target dataset. If M is too small, the dataset may not capture all the characteristics of the class, while if M is too large, the dataset may not capture all the characteristics of the class. If M is too large, it will increase the possibility of including poor quality samples. The larger the M value, the more likely it is to include poor quality samples, such as occlusion or blur, thereby weakening the representativeness of the dataset. Weakened the representativeness of the characteristics of this class.
[0069] Samples with smaller classification losses are more representative of the target class because they may show more prominent features. They may show more prominent features. Still select 200 known classes according to the above greedy strategy, but select different numbers of samples for each known class. In the ImageNet training data set, each class contains about 1300 pictures, and the class contains about 1300 images. The present invention will select 1, 130, 325, 650 and 1300 pictures with the smallest classification loss, and the classification loss of each known class is the smallest.
[0070] Figure 6 This is a comparison chart of the number of samples in each category and the success rate of attacking unknown categories in this embodiment. Figure 6 As shown in the figure, the number of samples in each class significantly affects the success rate of attacking unknown classes. As M increases from 1, the success rate of attacking unknown classes also increases. The success rate of attacking unknown classes will also increase. When M is set to 325, the white box attack success rate can reach up to 41.69%. Continuing to increase M does not improve the success rate of attacking unknown classes, and may even reduce the performance of attacking known classes. The performance of known classes. Therefore, in this embodiment, 325 is finally selected as the number of samples per known class of 423 for each known class. This decision emphasizes that the quantity and quality of target class samples are equally important.
[0071] The above data analysis and comparison proves that the method of the present invention can effectively attack unknown classes and known classes in various models.
[0072] Although the above describes the illustrative specific embodiments of the present invention to facilitate those skilled in the art to understand the present invention, it should be clear that the present invention is not limited to the scope of the specific embodiments. 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 using the concept of the present invention are protected.
Claims
1. A method for preparing a countermeasure sample based on universal potential infection, characterized in that: The following steps are involved: S1: According to actual needs, two image sample sets are obtained, namely the clean sample set C and the target sample set T. The clean sample set contains several clean samples x c , the target sample set contains several target samples x t , label each image sample with its corresponding category; S2: Classify the sample categories in the target sample set into known category sets y according to actual needs known and the unknown category set y unknown ; S3: The categories in the target sample set T belong to the known category set y known The target samples constitute the target sample set R; for each clean sample x in the clean sample set C c , randomly select a sample from the target sample set R that matches the clean sample x c Target samples x of different categories t , the clean sample x c and the target sample x t As training sample pairs, thus forming a training sample set; S4: Construct an adversarial sample generation model, including a feature extractor, a size matching module, and a generator, where: The feature extractor is used to extract features from the target sample and send the obtained target feature image to the size matching module; The size matching module is used to map the target feature images to the input image sizes of the K infection layers of the generator, and send the target feature images of K different sizes to the corresponding infection layers of the generator; The generator is used to generate adversarial samples x based on the input clean samples and K target feature images of different sizes. adv , wherein K layers are pre-selected as infection layers in each structural layer of the generator, and during the generation process, the original input features of each infection layer are superimposed with the received target feature image and then input into the infection layer for processing; S5: Use the training sample set to train the adversarial sample generation model to obtain a trained adversarial sample generation model; S6: For each clean sample x in the clean sample set C c , arbitrarily select a target sample with a different category from the target sample set T, and then input them into the adversarial sample generation model trained in step S5 to obtain an adversarial sample.
2. The method for preparing an adversarial sample according to claim 1, characterized in that: In step S4, the feature extractor uses a feature extraction module obtained by removing a classification head module from a pre-trained classification model.
3. The method for preparing an adversarial sample according to claim 1, characterized in that: In step S4, the generator adopts a U-Net network.
4. The method for preparing an adversarial sample according to claim 1, characterized in that: The calculation method of the loss function LOSS in the adversarial sample generation model training process in step S5 is as follows: LOSS=S(F(x adv ),F(x t ))+αS(F(δ),F(x t )) Among them, S() represents the feature similarity, F() represents feature extraction, δ = x adv -x c represents the bias image and α represents the weight hyperparameter.
5. The method for preparing an adversarial sample according to claim 4, characterized in that: The feature similarity adopts cosine distance.
Citation Information
Patent Citations
Open set category mining training method and system based on adversarial reciprocity point learning
CN113011469A
Confrontation-based bidirectional consistency constraint medical image registration algorithm
CN114359360A
Adversarial sample detection method and device, computer equipment and storage medium
CN116403079A
Method and device for generating adversarial sample image, and electronic equipment
CN116704313A
Attack method and device for collaborative confrontation of sample attack and backdoor attack
CN118313416A
