A method for defending against adversarial samples based on the combination of image preprocessing and adversarial training
By combining image preprocessing with adversarial training, adversarial features in deep neural networks are separated and processed, improving the model's robustness to adversarial examples while maintaining the recognition accuracy of the original images. This solves the problems of model fragility and accuracy degradation in existing technologies.
Patent Information
- Application Number
- CN202011383582.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-01
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2040-12-01
AI Technical Summary
Existing deep neural network models are vulnerable to adversarial examples, and existing defense methods, while improving the efficiency of adversarial example defense, lead to a decrease in the accuracy of original image recognition.
By combining image preprocessing and adversarial training, the original features and adversarial features are separated by performing DCT transformation and quantization table design on the image. Multiple classifiers are trained using different compression ratios and Gaussian noise, and the final result is obtained by voting.
This improves the robustness of deep neural networks to adversarial examples while maintaining the recognition accuracy of the original image, thus enhancing the defense efficiency against adversarial examples.
Smart Images

Figure CN112560901B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image processing and deep learning, and specifically relates to a method for improving the robustness of a neural network classifier against adversarial samples. Background Art
[0002] In image recognition and classification, the prediction results are often vulnerable to adversarial examples. Christian Szegedy et al. proposed the concept of adversarial examples, which are input samples formed by deliberately adding subtle noise to the data set. The disturbed input samples cause the model to give an erroneous output with high confidence. They found that deep learning models, including convolutional neural networks, are extremely vulnerable to adversarial examples.
[0003] In order to improve the robustness of Deep Neural Networks (DNN), the popular technologies are model-specific algorithms and model-agnostic algorithms. Model-specific algorithms include adversarial training and modifying network structure. Adversarial training is a method to defend against adversarial sample attacks. Training adversarial samples with normal samples is an effective regularization that can improve the accuracy of the model and effectively reduce the success rate of adversarial sample attacks. However, this defense is only for specific attack algorithms used to generate adversarial samples in the training set, and the above methods are difficult to change the highly linear characteristics of DNN. Model-agnostic algorithms mainly preprocess images before they are sent to DNN, including JPEG compression, total variance minimization, image quilting, etc. However, most image preprocessing methods will reduce the accuracy of DNN on the original image while improving a certain defense efficiency. Summary of the invention
[0004] Purpose of the invention: In order to overcome the shortcomings of the prior art, the present invention proposes a method for defending against adversarial samples based on a combination of image preprocessing and adversarial training, which improves the robustness of DNN to adversarial samples while maintaining the recognition accuracy of the original image.
[0005] Technical solution: The present invention proposes a method for defending against adversarial samples by using a neural network classifier based on a combination of image preprocessing and adversarial training, comprising the following steps:
[0006] 1) Divide the original image and adversarial sample into small blocks of n×n pixels, perform DCT transformation, and design a quantization table. The adversarial sample is a linear superposition of the original image and adversarial noise.
[0007] 2) Scale the quantization table proportionally to obtain the quantization table required to achieve different compression ratios, apply different compression ratios to the original image to compress it to obtain different data sets, then add noise as training adversarial samples. The original image and the training adversarial samples constitute the training data set, which is sent to the deep neural network for training to obtain different classifiers;
[0008] 3) The image to be classified is compressed with different compression ratios to obtain different images, and then sent to the classifier trained with the corresponding compression ratio data set, and the final result is obtained by voting by multiple classifiers.
[0009] Among them, the design method of the quantization table in the step 1) is as follows: perform variance analysis on the DCT frequency coefficients obtained after the original image and the adversarial sample are transformed by DCT, and divide all frequency coefficients into two groups: OF that is biased towards the original features and AF that is biased towards the adversarial features. For the OF group, a first quantization step size is designed that is mainly used to preserve the features, and for the AF group, a second quantization step size is designed that is mainly used to remove the adversarial features, and the first quantization step size is smaller than the second quantization step size.
[0010] Furthermore, the variance analysis includes: represents the variance of the DCT coefficients of the i-th row and j-th column of the original image, represents the variance of the DCT coefficients of the adversarial sample, represents the variance of the DCT coefficients of the adversarial noise, then use It represents the proportion of adversarial noise in the DCT coefficient of this frequency in the adversarial sample. The larger the r is, the more adversarial features the frequency coefficient carries. The DCT coefficients corresponding to r less than the specified threshold are taken as OF, and the rest are taken as AF.
[0011] Furthermore, the following loss function is used during training in step 2):
[0012] J'(θ,x,y)=ξ·J(θ,x,y)+(1-ξ)·J(θ,x q ,y)
[0013] Where θ represents the classifier weight parameter, x represents the original image, y represents the image classification label, ξ represents the learning rate, and x q Represents the image obtained by compressing the original image x with a compression ratio q and adding noise ρ.
[0014] Furthermore, the noise ρ satisfies a Gaussian distribution with a mean μ=0 and a variance σ=0.001.
[0015] Beneficial effects: The present invention proposes an image processing method for improving the robustness of DNN classifiers to adversarial samples from the perspective of combining image preprocessing and adversarial training. In order to enable DNN to improve the classification accuracy of adversarial samples while maintaining the accuracy on the original image, the present invention modifies the traditional JPEG algorithm, abandons the conversion of the color space, and redesigns the quantization table. In the image compression process, the original features are preserved to the greatest extent and the adversarial features are removed to improve the accuracy of the classifier. In addition, different compression ratios in the JPEG compression algorithm are used, and Gaussian noise is added as adversarial noise to obtain different training sets, and then different DNN models are trained, and the final results are obtained by voting. Compared with existing methods, this method can ensure the classification accuracy of the original image and improve the defense efficiency of adversarial samples. The present invention is suitable for applications that are sensitive to security, such as image classification and target detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a comparison between the traditional JPEG algorithm and the modified JPEG algorithm of the present invention;
[0017] Figure 2 The overall framework of the method for defending against adversarial samples based on the combination of image preprocessing and adversarial training provided in the embodiment of the present invention;
[0018] Figure 3 A schematic diagram of modifying a quantization table provided in an embodiment of the present invention;
[0019] Figure 4 The following is a display of subjective results of an experimental example provided for an embodiment of the present invention. DETAILED DESCRIPTION
[0020] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.
[0021] like Figure 1 and Figure 2 As shown, the present invention optimizes and modifies the traditional JPEG compression algorithm based on the principle of combining image preprocessing, adversarial training, and ensemble learning to make it more suitable for deep neural networks (DNNs); Gaussian noise is added as adversarial training samples on the basis of modifying the traditional JPEG algorithm, and different models are obtained by training different training sets obtained according to different compression ratios; the image to be classified enters the corresponding classifier model after preprocessing, and finally the outputs of multiple classifiers are combined by voting to obtain the final classification result. Thereby improving the robustness of the neural network classifier against adversarial samples.
[0022] The present invention is described in further detail below:
[0023] 1) Modify the traditional JPEG algorithm
[0024] In traditional JPEG compression, the RGB image to be compressed is often converted into the YCbCr space because the human eye is more sensitive to brightness differences than color changes. In machine learning, the features contained in each channel of the image are equally important, so the present invention abandons the conversion of color space in traditional JPEG compression. Figure 1 The modified JPEG algorithm shown in the lower row abandons the conversion from RGB to YCbCr color space designed based on HVS, divides the image into 8×8 small blocks, and compresses it using the modified quantization table after discrete cosine transform (DCT). It should be understood that dividing the image into 8×8 pixel blocks here is only an example and does not limit the present invention. In other embodiments, the image can also be divided according to other pixel levels, such as 4×4, 16×16, etc.
[0025] 2) Modification of quantization table
[0026] By performing variance analysis on the 64 frequency coefficients (1 DC coefficient and 63 AC coefficients) obtained after DCT transformation of the original image and the adversarial sample, the 64 frequency coefficients are divided into two groups: OF, which is biased towards the original features, and AF, which is biased towards the adversarial features. The quantization table is redesigned. A smaller quantization step size is used for OF to preserve the features, and a larger quantization step size is used for AF to remove the adversarial features.
[0027] Specifically, since the adversarial sample is a linear superposition of the original image and adversarial noise, the 64 DCT coefficients of the 8×8 blocks divided into the adversarial sample after DCT transformation are also the linear superposition of the DCT coefficients of the corresponding 8×8 blocks in the original image and adversarial noise after DCT transformation. Represents the variance of the DCT frequency coefficient of the i-th row and j-th column (i<8, j<8) of the original image, represents the variance of the DCT coefficients of the adversarial sample, represents the variance of the DCT coefficients of the adversarial noise, then use Indicates the proportion of adversarial noise in the DCT coefficient of this frequency in the adversarial sample. The larger the r, the more adversarial features the frequency coefficient carries. The 64 frequency coefficients are arranged in ascending order according to the size of r, and the 64 frequency coefficients are divided into two groups. The group with smaller r means that it carries fewer adversarial features and more original features. The DCT coefficients corresponding to r less than the specified threshold are taken as OF, and a smaller quantization step is designed for this group. Otherwise, the remaining frequency coefficients are another group AF, and a larger quantization step is designed to remove adversarial noise. The quantization step is used to quantize the DCT coefficients to achieve the purpose of lossy compression. Such as Figure 3As shown, the upper left corner is the OF band, indicating that this part of the frequency coefficients tends to carry more original features, and the rest is the AF band, indicating that this part of the frequency coefficients tends to carry more adversarial features.
[0028] 3) Adversarial training and ensemble learning
[0029] Quantization tables corresponding to different compression ratios can be obtained by using the original scaling function of JPEG and the modified quantization table. The compression ratio is the scaling factor of the quantization table, which controls the step size of the entire quantization table and thus controls the degree of compression of the image. Different compression ratios can be used as a way of data augmentation to obtain multiple different training sets. The original public ImageNet data set is applied to the quantization tables corresponding to different compression ratios to obtain training sets with different image qualities. Digital images usually use 8 bits of precision (0-255 integers) to save images, so any information below 1 / 255 will be discarded. Based on this, the present invention designs an algorithm for defending against adversarial samples based on a neural network classifier combined with image preprocessing and adversarial training. We expect that when |ρ|<1 / 255, the classifier's output prediction results for the input images x and x+ρ are the same. Therefore, Gaussian noise is added to the training set as adversarial noise ρ (mean μ=0, variance σ=0.001) as a training adversarial sample. The loss function defined in the training process is:
[0030] J'(θ,x,y)=ξ·J(θ,x,y)+(1-ξ)·J(θ,x q ,y)
[0031] Where θ represents the classifier weight parameter, x represents the input original image, y represents the image classification label, ξ is set to 0.9 for faster convergence, and x q It represents the image obtained by compressing the original image x by compression ratio q and adding Gaussian noise ρ, where ρ takes mean μ=0 and variance σ=0.001 to ensure that the absolute value of each pixel of the noise is less than 1 / 255 to meet the above analysis.
[0032] Different training sets obtained in the above steps train different classifier models. Different classifiers all use the Inception-v4 network structure of GoogleNet, but the internal network parameters obtained by training on data sets with different compression qualities are different.
[0033] 4) The image to be classified is compressed at different compression ratios to obtain different images and sent to the classifier trained with the corresponding compression ratio data set in step 3), and the final result is obtained by voting of multiple classifiers.
[0034] The performance of this method is verified by an experiment below. Without loss of generality, the images in the ImageNet dataset are used for testing. The classifier used in the test adopts the Inception-v4 structure of GoogleNet. The classifier set is composed of the original Inception-v4 model and five sub-classifiers (model 0, model 1, model 2, model 3, model 4) obtained by fine-tuning the four ImageNet datasets processed with compression qualities of 90, 70, 50, and 30 respectively.
[0035] A random original image is selected from ImageNet and classified into the correct class seasnake by the Inception-v4 network. Four adversarial sample images are generated using four attack methods (FGSM, BIM, Deepfool, CW), such as Figure 4 , the four adversarial samples were all misclassified after entering the original GoogleNet’s Inception-v4 neural network structure.
[0036] When this method is used to classify images, the adversarial samples are applied as follows Figure 1 The modified JPEG algorithm shown in the lower row abandons the conversion from RGB to YCbCr color space designed based on HVS, divides the image into 8×8 small blocks, and uses the modified quantization table after DCT transformation to compress the image with QF=90, 70, 50, and 30, respectively. Together with the original image, 5 images of different qualities are obtained. These 5 images are sent to the corresponding classifiers in the classifier set for recognition, and the final result is obtained by voting by the 5 sub-classifiers. The results show that this method can correctly recognize the above four adversarial samples.
Claims
1. A method for defending against adversarial samples based on the combination of image preprocessing and adversarial training. It is characterized in that The method comprises the following steps: 1) The original image and the adversarial sample are divided into small blocks of n×n pixels, DCT transformation is performed, and a quantization table is designed. The adversarial sample is formed by linear superposition of the original image and the adversarial noise. The design method of the quantization table is as follows: variance analysis is performed on the DCT frequency coefficients obtained after the original image and the adversarial sample are transformed by DCT, and all frequency coefficients are divided into two groups: OF biased towards the original features and AF biased towards the adversarial features. For the OF group, a first quantization step size is designed mainly for preserving the features, and for the AF group, a second quantization step size is designed mainly for removing the adversarial features, and the first quantization step size is smaller than the second quantization step size; 2) Scale the quantization table proportionally to obtain the quantization table required to achieve different compression ratios, apply different compression ratios to the original image to compress it to obtain different data sets, then add noise as training adversarial samples. The original image and the training adversarial samples constitute the training data set, which is sent to the deep neural network for training to obtain different classifiers. The following loss function is used during training: J , (θ,x,y)=ξ·J(θ,x,y)+(1-ξ)·J(θ,x q ,y) Where θ represents the classifier weight parameter, x represents the original image, y represents the image classification label, ξ represents the learning rate, and x q It represents the image obtained by compressing the original image x by compression ratio q and adding noise ρ; 3) The image to be classified is compressed with different compression ratios to obtain different images, and then sent to the classifier trained with the corresponding compression ratio data set, and the final result is obtained by voting by multiple classifiers.
2. The method for defending against adversarial samples based on the combination of image preprocessing and adversarial training according to claim 1, It is characterized in that The variance analysis includes: represents the variance of the DCT coefficients of the i-th row and j-th column of the original image, represents the variance of the DCT coefficients of the adversarial sample, represents the variance of the DCT coefficients of the adversarial noise, then use It represents the proportion of adversarial noise in the DCT coefficient of this frequency in the adversarial sample. The larger the r is, the more adversarial features the frequency coefficient carries. The DCT coefficients corresponding to r less than the specified threshold are taken as OF, and the rest are taken as AF.
3. The method for defending against adversarial samples based on the combination of image preprocessing and adversarial training according to claim 1, It is characterized in that The noise ρ satisfies a Gaussian distribution with a mean μ=0 and a variance σ=0.001.
