Method and device for generating adversarial image based on semantic transformation

The method of generating adversarial images through semantic transformation solves the problem of low migration of adversarial samples in deep neural networks, improves the migration and generation efficiency of adversarial images, and enhances security.

CN119048817AActive Publication Date: 2024-11-29HUAZHONG UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411129020.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-16
Publication Date
2024-11-29
Estimated Expiration
2044-08-16

AI Technical Summary

Technical Problem

Deep neural networks are susceptible to adversarial samples. The existing migration-based black box attack methods have low anti-adversarial samples and cannot effectively identify potential vulnerabilities between different models, resulting in security threats.

Method used

By acquiring the source model, original image and its category labels, establishing data distribution, performing semantic transformation to generate multiple semantic enhancement images, calculating the average gradient to update the adversarial image, repeating iteration until the preset stop condition is reached, improving the migration of the adversarial image.

Benefits of technology

The migration and generation efficiency of adversarial images are improved, computational costs are reduced, and the use of high-cost generative models is avoided, which enhances the diversity of adversarial samples.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119048817A_ABST
    Figure CN119048817A_ABST
Patent Text Reader

Abstract

The invention discloses a method and a device for generating an adversarial image based on semantic transformation. The method comprises the following steps: acquiring a source model, an original image and a category label corresponding to the original image; establishing data distribution based on the plurality of obtained reference images belonging to the category labels; performing semantic transformation on the original image based on data distribution to obtain a plurality of semantic enhanced images; inputting the plurality of semantic enhancement images into the source model, and calculating an average gradient; calculating an update gradient based on the average gradient; updating and cutting the original image based on the updating gradient to obtain a confrontation image; and based on the confrontation image, re-executing the steps of performing semantic transformation on the confrontation image based on the data distribution to obtain a plurality of new semantic enhancement images and obtaining a new confrontation image according to the plurality of new semantic enhancement images until a preset stop condition is met, and obtaining an optimized confrontation image. According to the method, the diversity of transformed images is increased by using semantic transformation, so that the mobility of adversarial images is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention particularly relates to a method and device for generating adversarial images based on semantic transformation. Background Art

[0002] With the rapid development of deep learning technology, deep neural networks have achieved great success in tasks such as image classification and object detection, and have been widely used in security-critical scenarios such as security monitoring, autonomous driving, face recognition, and remote sensing detection. However, studies have found that deep neural networks are vulnerable to adversarial samples. Adversarial samples add artificially designed small perturbations to cause the model to produce incorrect recognition results, such as self-driving cars failing to recognize stop signs or face recognition systems being misled, leading to serious consequences.

[0003] Adversarial attacks are divided into white-box attacks and black-box attacks. In white-box attacks, the attacker has model information and can easily generate adversarial samples by calculating gradients. However, in reality, the target model is mostly private and it is difficult to obtain relevant information. To this end, researchers have developed black-box attack methods based on query and migration. The query-based method is less efficient, while the migration-based method has higher practicality and has received widespread attention by generating adversarial samples on the source model and migrating them to the target model. Attackers can easily attack black-box models of unknown architecture and parameters using adversarial samples with transferability, posing a huge threat to many real-world applications based on deep neural networks.

[0004] Therefore, it is crucial to study the transferability of adversarial samples, which will help identify potential weaknesses of deep neural networks, promote the development of adversarial defense algorithms, improve the robustness of models, and provide guarantees for the safe application of artificial intelligence technology. We will strengthen digital security, strengthen national strategic scientific and technological strength, and conquer key core technologies. Summary of the invention

[0005] In order to obtain a better adversarial image, an embodiment of the present invention provides a method and device for generating an adversarial image based on semantic transformation.

[0006] In a first aspect, an embodiment of the present invention provides a method for generating an adversarial image based on semantic transformation, which may include:

[0007] Get the source model, original image and its corresponding category label;

[0008] Establishing a data distribution based on a plurality of reference images belonging to the category label obtained;

[0009] Based on the data distribution, performing semantic transformation on the original image to obtain a plurality of semantically enhanced images;

[0010] Input the multiple semantically enhanced images into the source model and calculate the average gradient;

[0011] Calculate an updated gradient based on the average gradient;

[0012] Update the original image based on the updated gradient and crop it to obtain an adversarial image;

[0013] Based on the adversarial image, the above steps of performing semantic transformation on the adversarial image based on the data distribution to obtain multiple new semantically enhanced images, and obtaining new adversarial images based on the multiple new semantically enhanced images are re-executed until a preset stopping condition is reached to obtain an optimized adversarial image.

[0014] In one or some optional implementations of the embodiments of the present application, the semantic transformation of the original image based on the data distribution to obtain multiple semantically enhanced images includes:

[0015] Perform feature extraction based on the original image to obtain original deep features;

[0016] Performing multiple random samplings on the data distribution to obtain multiple semantic transformation directions;

[0017] Based on each semantic transformation direction, transform the original deep features to obtain semantically transformed image features;

[0018] The original image is optimized according to the original deep features and the image features after semantic transformation to obtain a semantically enhanced image.

[0019] In one or some optional implementations of the embodiments of the present application, optimizing the original image according to the original deep features and the image features after semantic transformation to obtain a semantically enhanced image includes:

[0020] According to the original deep features and the image features after semantic transformation, the original image is optimized by the following formula to obtain a semantically enhanced image:

[0021]

[0022] In the formula, represents the semantically enhanced image, x represents the original image, is the total change loss, which is composed of L2 loss and smoothing loss Composition, a is the original deep feature, is the image feature after semantic transformation, where the smoothing loss It can be calculated by the following formula:

[0023]

[0024] In the formula, represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column, represents the pixel value of the semantically enhanced image in the i-th row and j-th column, Represents the pixel value of the semantically enhanced image in the i+1th row and jth column.

[0025] In one or some optional implementations of the embodiments of the present application, the step of inputting the multiple semantically enhanced images into the source model and calculating the average gradient includes:

[0026] Inputting the multiple semantically enhanced images into the source model, and calculating a loss value corresponding to each semantically enhanced image;

[0027] Calculate the gradient of each semantically enhanced image according to the loss value corresponding to each semantically enhanced image;

[0028] Based on the gradient corresponding to each semantically enhanced image, the mean is calculated based on the following formula to obtain the average gradient:

[0029]

[0030] In the formula, is the average gradient, K is the total number of semantically enhanced images, Enhance images for semantics The corresponding gradient, Enhance images for semantics The corresponding loss value, y is the category label.

[0031] In one or some optional implementations of the embodiments of the present application, establishing data distribution based on the acquired multiple reference images belonging to the category label includes:

[0032] Acquire multiple reference images belonging to the category label;

[0033] Performing feature extraction based on the multiple reference images to obtain multiple reference deep features;

[0034] A data distribution is established based on the plurality of reference deep features.

[0035] In one or some optional implementations of the embodiments of the present application, the updating gradient is obtained based on the average gradient calculation, including:

[0036] The update gradient is calculated based on the average gradient and the update gradient of the previous round by the following formula:

[0037]

[0038] In the formula, g t is the updated gradient, μ is the preset momentum factor, g t-1 is the last updated gradient, where the first iteration is g t-1 The value is 0, is the average gradient.

[0039] In one or some optional implementations of the embodiments of the present application, updating the original image based on the updated gradient and cropping it to obtain the adversarial image includes:

[0040] Update the original image based on the updated gradient and the preset step size parameter to obtain an initial adversarial image;

[0041] The initial adversarial image is cropped based on a preset disturbance threshold to obtain an adversarial image.

[0042] In a second aspect, an embodiment of the present invention provides a device for generating an adversarial image based on semantic transformation, which may include:

[0043] The first acquisition module is used to acquire the source model, the original image and its corresponding category label;

[0044] A first establishing module, used for establishing data distribution based on a plurality of reference images obtained and belonging to the category label;

[0045] A semantic transformation module, used for performing semantic transformation on the original image based on the data distribution to obtain a plurality of semantically enhanced images;

[0046] A first calculation module, used for inputting the plurality of semantically enhanced images into the source model and calculating an average gradient;

[0047] A second calculation module, used to calculate an update gradient based on the average gradient;

[0048] A first updating module, configured to update and crop the original image based on the updated gradient to obtain an adversarial image;

[0049] The first judgment module is used to judge whether the preset stop condition is met: if so, an optimized adversarial image is obtained; if not, the semantic transformation module, the first calculation module, the second calculation module and the first update model are used to re-execute the process of obtaining a new adversarial image.

[0050] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program / instruction stored thereon, which, when executed by a processor, implements the method for generating adversarial images based on semantic transformation as described above.

[0051] In a fourth aspect, an embodiment of the present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the method for generating an adversarial image based on semantic transformation as described above.

[0052] In a fifth aspect, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein when the processor executes the computer program, the method for generating adversarial images based on semantic transformation as described above is implemented.

[0053] The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least:

[0054] The embodiment of the present invention provides a method for generating adversarial images based on semantic transformation, which obtains a source model, an original image and its corresponding category label, and establishes a data distribution based on multiple reference images of the same category label, performs semantic transformation on the original image, obtains multiple semantically enhanced images, inputs the multiple semantically enhanced images into the source model, calculates the average gradient, thereby determining the updated gradient, obtains the adversarial image, repeatedly performs semantic transformation based on the adversarial image to obtain multiple new semantically enhanced images, and obtains the new adversarial image step until a preset stop condition is reached to obtain an optimized adversarial image. In the process of iterative optimization of the adversarial image, the method transforms the image at the semantic level to increase the diversity of the transformed image, thereby improving the mobility of the adversarial image. At the same time, the method only generates very little computational cost during semantic transformation, avoids the use of a computationally expensive generation model, and can effectively improve the generation efficiency of adversarial samples.

[0055] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description and the accompanying drawings.

[0056] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0058] Figure 1 A schematic diagram of the steps of a method for generating an adversarial image based on semantic transformation provided by an embodiment of the present invention;

[0059] Figure 2 An example schematic diagram of obtaining multiple semantically enhanced images through semantic transformation provided by an embodiment of the present invention;

[0060] Figure 3 An example schematic diagram of an adversarial image updating method based on semantic transformation provided by an embodiment of the present invention;

[0061] Figure 4 A schematic diagram of the structure of an apparatus for generating adversarial images based on semantic transformation provided in an embodiment of the present application. DETAILED DESCRIPTION

[0062] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0063] The inventors found that in the prior art, the black-box attack method based on transfer often overfits to the source model, resulting in low transferability of the generated adversarial samples. Therefore, the degree of transferability represents whether the adversarial sample can effectively identify potential vulnerabilities between different models. In recent years, in order to improve the transferability of adversarial samples, researchers have proposed numerous adversarial attack methods. Studies have found that the higher the diversity of the transformed images, the higher the transferability of the adversarial samples. However, most of the existing input transformation methods use some simple spatial transformation strategies, such as random resizing, translation, and mixing of different images. Although these transformation techniques can effectively improve the transferability of adversarial samples, they can only change the spatial structure of the image, but cannot change the semantic content of the original image, such as the color, posture, and angle of the background or foreground objects of the image, thus limiting the diversity of the transformed images, resulting in limited transferability.

[0064] Based on this, the inventors have made the present invention after further research and development, providing a method and device for generating adversarial images based on semantic transformation.

[0065] Embodiment 1

[0066] In the first embodiment of the present invention, a method for generating an adversarial image based on semantic transformation is provided. Figure 1 As shown, the method may include the following steps S101-S108:

[0067] S101: Obtain a source model, an original image and its corresponding category label.

[0068] S102: Establishing data distribution based on multiple reference images belonging to category labels obtained.

[0069] S103: Based on the data distribution, semantic transformation is performed on the original image to obtain multiple semantically enhanced images.

[0070] S104: Input multiple semantically enhanced images into the source model and calculate the average gradient.

[0071] S105: Obtain an updated gradient based on the average gradient calculation.

[0072] S106: Update the original image based on the updated gradient and crop it to obtain an adversarial image.

[0073] S107: Determine whether the preset stop condition is met: if so, execute step S108; if not, re-execute steps S103-S106 based on the adversarial image.

[0074] S108: Obtain an optimized adversarial image.

[0075] The embodiment of the present invention provides a method for generating adversarial images based on semantic transformation, which obtains a source model, an original image and its corresponding category label, and establishes a data distribution based on multiple reference images of the same category label, performs semantic transformation on the original image, obtains multiple semantically enhanced images, inputs the multiple semantically enhanced images into the source model, calculates the average gradient, thereby determining the updated gradient, obtains the adversarial image, repeatedly performs semantic transformation based on the adversarial image to obtain multiple new semantically enhanced images, and obtains the new adversarial image step until a preset stop condition is reached to obtain an optimized adversarial image. In the process of iterative optimization of the adversarial image, the method transforms the image at the semantic level to increase the diversity of the transformed image, thereby improving the mobility of the adversarial image. At the same time, the method only generates very little computational cost during semantic transformation, avoids the use of a computationally expensive generation model, and can effectively improve the generation efficiency of adversarial samples.

[0076] Here we first discuss the technical problems that need to be solved in this field:

[0077] For the original image x and its corresponding category label y, obtain the source model f(), which is a classification model used to output a predicted label for the image. In this field, the goal is to generate an adversarial image x based on the original image x. adv , so that the adversarial image x adv Deceive the source model f() so that the prediction result output by the source model f() is not equal to y, that is, f(x adv )≠y.

[0078] At the same time, the adversarial image has only a tiny perturbation relative to the original image, which is enough to make the deep learning model (such as a neural network) produce wrong predictions or classification results, but it is almost imperceptible to human observers. This perturbation is called adversarial perturbation in this field and is represented by L pThe norm measures the size of the adversarial perturbation, and uses a preset perturbation threshold ∈ to achieve the imperceptibility of the perturbation, that is, ||x adv -x|| p ≤∈, where p is a parameter in the norm, used to define different norms. Therefore, the optimization problem of generating samples can be expressed as the following formula 1:

[0079]

[0080] In the formula, J(x adv ,y) represents the classification loss function of the source model.

[0081] In order to solve the optimization problem shown in Formula 1 above, it is necessary to calculate the gradient of the classification loss function relative to the input image. However, only using the gradient from a single image to update the adversarial sample is prone to overfitting to the source model f(), resulting in poor transferability. In order to improve the transferability of adversarial samples, some studies have proposed an adversarial sample generation method based on input transformation. This method refers to transforming the image before calculating the gradient, and using the gradients from multiple transformed images to update the adversarial sample, which effectively alleviates the overfitting of the adversarial sample to the source model. It is one of the most effective methods to improve transferability. However, most of the existing input transformation methods use simple spatial transformations, which only change the spatial structure of the image but cannot change the semantic content of the original image. Therefore, the diversity of the transformed image is limited, resulting in limited transferability. Therefore, the present invention proposes a method for generating adversarial images based on semantic transformation.

[0082] The following is a step-by-step explanation of the specific implementation steps of this application:

[0083] In the above step S101, the source model f(), the original image x and its corresponding category label y are obtained. For example, the source model f() is an open source image classification model ViT (Vision Transformers), the original image x is an image of a bird, and the corresponding category label y is "bird".

[0084] In the above step S102, based on the obtained multiple reference images belonging to the category label, a data distribution is established, which specifically includes the following steps S1021-S1023:

[0085] S1021: Acquire multiple reference images belonging to a category label.

[0086] Specifically, it can be to collect N reference images {x 1 ,x 2 ,x 3 ,...,x N}, for example, collect 1000 reference images with class label y as “bird”.

[0087] S1022: Perform feature extraction based on multiple reference images to obtain multiple reference deep features.

[0088] Specifically, it can be that N reference images {x 1 ,x 2 ,x 3 ,...,x N} respectively input into the feature extraction model to obtain N reference deep features {a 1 ,a 2 ,a 3 ,...,a N Among them, the feature extraction model can use open source models in the image field, such as VGGNet, ViT, etc.

[0089] In a specific embodiment, VGGNet is used as a feature extraction model, and the reference image is input into the feature extraction model. The specific steps of obtaining the reference deep features include: loading the pre-trained VGGNet from the Pytorch model library, removing the last fully connected layer of VGGNet, retaining the convolutional layer for extracting deep features, and then inputting the reference image into the processed VGGNet to obtain the reference deep features.

[0090] S1023: Establish data distribution based on multiple reference deep features.

[0091] Specifically, it can be, based on N reference deep features {a 1 ,a 2 ,a 3 ,...,a N} Calculate the covariance, and then establish a data distribution based on the covariance. The data distribution can be a zero-mean multivariate normal distribution N(0,Σy).

[0092] The covariance is calculated by the following formula 2:

[0093]

[0094] In the formula, ∑y represents the covariance of the reference deep feature with category label y, x j is the jth reference deep feature, and μ is the mean of all reference deep features.

[0095] Of course, in some other embodiments, the data distribution may also take other forms, such as a multivariate normal distribution with a non-zero mean.

[0096] In the embodiment of the present application, feature extraction is performed based on multiple reference images and data distribution is established. In the data distribution, the mean is used to represent the commonality of the images of the category label, and the covariance is used to represent the range of variation (color, shape, posture, etc.) of the image semantics of the category label, or the feature distribution. The data distribution contains rich potential semantic transformation information. Therefore, for images with the same category label, the effective semantic transformation direction can be well represented by the data distribution.

[0097] Among them, the effective semantic transformation direction means that the category label of the image before and after the semantic transformation has not changed. Since the goal of this field is to mislead the source model or the target attack model to produce an incorrect classification result, the gradient direction of the source model for the input image should point from the original class to other classes, for example, from "bird" to "cat". However, if the category label of the image after the semantic transformation changes before the attack, the gradient direction of the source model will become from other classes to other classes, for example, from "cat" to "cat", which has nothing to do with the category label "bird" of the original image, resulting in inaccurate gradient direction, and inaccurate gradient direction will affect the attack success rate of the adversarial sample, resulting in reduced transferability. Therefore, the semantic transformation cannot change the category label of the image, that is, the bird in the original image should not be converted into objects of other categories such as cars and airplanes.

[0098] In the above step S103, multiple random samplings are performed based on data distribution, and semantic transformation is performed on the original image to obtain multiple semantically enhanced images. Specifically, the following steps S1031-S1034 are included:

[0099] S1031: Extract features based on the original image to obtain original deep features.

[0100] Specifically, the original image x may be input into the feature extraction model to obtain the original deep feature a. The feature extraction model may use an open source model in the image field, such as VGGNet, ViT, etc. The specific steps of using the feature extraction model to extract features have been described in the above step S1022 and will not be repeated here.

[0101] S1032: Perform multiple random samplings on the data distribution to obtain multiple semantic transformation directions.

[0102] Specifically, it can be that a random sampling is performed on the data distribution to obtain a semantic transformation direction w~N(0,Σy), and the random sampling is repeated K times to obtain K semantic transformation directions Wherein, K is a positive integer, for example, it can be set to 20.

[0103] S1033: Based on each semantic transformation direction, the original deep features are transformed to obtain the image features after the semantic transformation.

[0104] Specifically, it can be based on each semantic transformation direction w k , based on the following formula 3, the original deep features are interpolated and transformed to obtain the image features after semantic transformation

[0105]

[0106] In the formula, represents the image features after semantic transformation, and λ represents the preset semantic enhancement strength parameter.

[0107] S1034: Optimize the original image according to the original deep features and the image features after semantic transformation to obtain a semantically enhanced image.

[0108] Specifically, it can be, based on the original deep feature a and the image feature after semantic transformation The original image x is optimized by the following formula 4 to obtain the semantically enhanced image

[0109]

[0110] In the formula, represents the semantically enhanced image, x represents the original image, is the total change loss, which is composed of L2 loss and smoothing loss Composition, a is the original deep feature, is the image feature after semantic transformation, where the smoothing loss It can be calculated by the following formula:

[0111]

[0112] In the formula, represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column, represents the pixel value of the semantically enhanced image in the i-th row and j-th column, Represents the pixel value of the semantically enhanced image in the i+1th row and jth column.

[0113] In the embodiment of the present application, sampling is performed on the data distribution to obtain effective semantic transformation directions, and feature interpolation is performed to obtain features after semantic transformation, which are used to optimize the pixels of the original image so that the features of the original image are aligned with the semantic transformation features to obtain a semantically enhanced image. This method will only generate very little computational cost in the feature interpolation process, and does not need to follow the conventional image semantic transformation method to manually annotate the data set and then train an expensive generation model. In the prior art, by manually annotating methods, by collecting images with different semantic contents, multiple semantic labels are marked for different semantic directions. For example, for human images, different semantic labels may include wearing glasses, growing a beard, different hair colors, etc., and then different semantic change directions are obtained by calculating the mean of image features of different semantic labels. However, this process requires a lot of manual work to collect and annotate images, and it is difficult to exhaust the different semantic directions of objects of different categories by relying on manual annotation. This method avoids the huge labor cost caused by collecting different semantic images and labels, and can effectively improve the generation efficiency of adversarial samples.

[0114] In order to facilitate those skilled in the art to understand the present solution, the specific implementation of step S103 provided in the embodiment of the present application is described more clearly and completely by way of example below, with reference to Figure 2 As shown, from left to right is the execution order of step S103. The left virtual box is the representation of multiple reference deep features with the category label "bird" in the feature space. By calculating the intra-class covariance, establishing the data distribution, sampling multiple semantic transformation directions, and performing semantic transformation, the three semantically enhanced images on the right are obtained. It can be seen that the category label of the three semantically enhanced images is still "bird", but the semantic information such as the bird's position, shape, texture, and image background has changed, achieving an effective semantic transformation.

[0115] In the above step S104, multiple semantically enhanced images are input into the source model to calculate the average gradient, which specifically includes the following steps S1041-S1043:

[0116] S1041: Input multiple semantically enhanced images into the source model, and calculate the loss value corresponding to each semantically enhanced image.

[0117] Specifically, the K semantically enhanced images obtained in step S103 above may be Input the source model f(), and then calculate the loss value corresponding to each semantically enhanced image according to the loss function in the source model f() For example, when the loss function in the source model is the cross entropy loss function, the semantically enhanced image The corresponding loss value calculation formula is shown in the following formula 6:

[0118]

[0119] In the formula, Enhance images for semantics The corresponding loss value is Predicting semantically enhanced images for source models The probability of belonging to class label y.

[0120] S1042: Calculate the gradient corresponding to each semantically enhanced image according to the loss value corresponding to each semantically enhanced image.

[0121] Specifically, it can be, according to the semantic enhancement image The corresponding loss value is calculated to obtain the corresponding gradient. Those skilled in the art can use the detailed introduction of the prior art, such as using the backward() function in the Pytorch deep learning framework, to calculate the gradient based on the loss value.

[0122] S1043: Based on the gradient corresponding to each semantically enhanced image, the mean is calculated based on the following formula 7 to obtain an average gradient:

[0123]

[0124] In the formula, is the average gradient, K is the total number of semantically enhanced images, Enhance images for semantics The corresponding gradient, Enhance images for semantics The corresponding loss value, y is the category label, and t represents the iteration round.

[0125] In the above step S105, the update gradient is calculated based on the average gradient. Specifically, the update gradient may be calculated based on the average gradient and the update gradient of the previous round by the following formula 8:

[0126]

[0127] In the formula, g t is the updated gradient, μ is the preset momentum factor, g t-1 is the last updated gradient, where the first iteration is g t-1 The value is 0, is the average gradient, and t represents the iteration round.

[0128] In the above step S106, the original image is updated and cropped based on the updated gradient to obtain an adversarial image, which specifically includes the following steps S1061-S1062:

[0129] S1061: Update the original image based on the updated gradient and the preset step size parameter using the following formula 9 to obtain an initial adversarial image:

[0130]

[0131] In the formula, is the initial adversarial image, is the previous adversarial image, where it is 0 in the first iteration, α is the step size (or learning rate) parameter in each iteration, and sign() is the sign function used to obtain the updated gradient g t The direction of , t represents the iteration round.

[0132] S1062: Based on a preset disturbance threshold, the initial adversarial image is cropped using the following formula 10 to obtain an adversarial image:

[0133]

[0134] In the formula, is the adversarial image, and clip{} is the cropping function used to convert the initial adversarial image The data is limited to the specified range [x, ∈], ∈ is the preset disturbance threshold, which is used to limit the size of the disturbance and achieve the imperceptibility of the disturbance, and t represents the iteration round.

[0135] In order to facilitate those skilled in the art to understand the present solution, the specific implementation of steps S103-S106 provided in the embodiment of the present application is described more clearly and completely by way of example. Figure 3 As shown, from left to right is the execution order of steps S103-S106, the input image is semantically transformed to obtain K transformed images, which are input into the classification model, the gradient is calculated, and the input image is updated based on the gradient to obtain the adversarial sample, where the input image corresponds to the original image mentioned above, the transformed image corresponds to the semantically enhanced image mentioned above, the classification model corresponds to the source model mentioned above, and the gradient corresponds to the updated gradient mentioned above.

[0136] In the above step S107, it is determined that the preset stop condition is reached, which specifically includes the following steps S1071-S1073:

[0137] S1071: Determine whether the preset stop condition is met: if so, execute step S1072; if not, execute step S1073.

[0138] S1072: Return the adversarial image obtained in the latest iteration round.

[0139] S1073: Adversarial image obtained based on the current iteration round Re-execute the above steps S103-S106 to analyze the adversarial image based on data distribution. Perform semantic transformation to obtain multiple new semantically enhanced images, and obtain new adversarial images based on the multiple new semantically enhanced images steps.

[0140] The preset stop condition may be set to reaching a fixed number of iterations, the mobility of the adversarial image reaching a threshold, etc. No specific limitation is given here.

[0141] Embodiment 2

[0142] Based on the same inventive concept, the embodiment of the present invention also provides a device for generating an adversarial image based on semantic transformation, referring to Figure 4 As shown, the device comprises:

[0143] The first acquisition module is used to acquire the source model, the original image and its corresponding category label;

[0144] A first establishing module, used for establishing data distribution based on a plurality of reference images obtained and belonging to the category label;

[0145] A semantic transformation module, used for performing semantic transformation on the original image based on the data distribution to obtain a plurality of semantically enhanced images;

[0146] A first calculation module, used for inputting the plurality of semantically enhanced images into the source model and calculating an average gradient;

[0147] A second calculation module, used to calculate an update gradient based on the average gradient;

[0148] A first updating module, configured to update and crop the original image based on the updated gradient to obtain an adversarial image;

[0149] The first judgment module is used to judge whether the preset stop condition is met: if so, an optimized adversarial image is obtained; if not, the semantic transformation module, the first calculation module, the second calculation module and the first update model are used to re-execute the process of obtaining a new adversarial image.

[0150] Embodiment 3

[0151] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, the method for generating an adversarial image based on semantic transformation as described in the above-mentioned embodiment 1 is implemented.

[0152] Embodiment 4

[0153] Based on the same inventive concept, an embodiment of the present invention further provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the method for generating an adversarial image based on semantic transformation as described in the above-mentioned embodiment 1.

[0154] Embodiment 5

[0155] Based on the same inventive concept, an embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory. When the processor executes the computer program, the method for generating adversarial images based on semantic transformation as described in the above embodiment 1 is implemented.

[0156] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0157] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0158] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0159] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0160] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for generating adversarial images based on semantic transformation, characterized in that: include: Get the source model, original image and its corresponding category label; Establishing a data distribution based on a plurality of reference images belonging to the category label obtained; Based on the data distribution, performing semantic transformation on the original image to obtain a plurality of semantically enhanced images; Input the multiple semantically enhanced images into the source model and calculate the average gradient; Calculate an updated gradient based on the average gradient; Update the original image based on the updated gradient and crop it to obtain an adversarial image; Based on the adversarial image, the above steps of performing semantic transformation on the adversarial image based on the data distribution to obtain multiple new semantically enhanced images, and obtaining new adversarial images according to the multiple new semantically enhanced images are re-executed until a preset stopping condition is reached to obtain an optimized adversarial image.

2. The method according to claim 1, characterized in that The semantic transformation of the original image based on the data distribution to obtain a plurality of semantically enhanced images includes: Perform feature extraction based on the original image to obtain original deep features; Performing multiple random samplings on the data distribution to obtain multiple semantic transformation directions; Based on each semantic transformation direction, transform the original deep features to obtain semantically transformed image features; The original image is optimized according to the original deep features and the image features after semantic transformation to obtain a semantically enhanced image.

3. The method according to claim 2, characterized in that The step of optimizing the original image according to the original deep features and the image features after semantic transformation to obtain a semantically enhanced image includes: According to the original deep features and the image features after semantic transformation, the original image is optimized by the following formula to obtain a semantically enhanced image: In the formula, represents the semantically enhanced image, x represents the original image, is the total change loss, which is composed of L2 loss and smoothing loss Composition, a is the original deep feature, is the image feature after semantic transformation, where the smoothing loss It can be calculated by the following formula: In the formula, represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column, represents the pixel value of the semantically enhanced image in the i-th row and j-th column, Represents the pixel value of the semantically enhanced image in the i+1th row and jth column.

4. The method according to claim 1, characterized in that: The step of inputting the plurality of semantically enhanced images into the source model and calculating the average gradient comprises: Inputting the multiple semantically enhanced images into the source model, and calculating a loss value corresponding to each semantically enhanced image; According to the loss value corresponding to each semantically enhanced image, the gradient corresponding to each semantically enhanced image is calculated; Based on the gradient corresponding to each semantically enhanced image, the mean is calculated based on the following formula to obtain the average gradient: In the formula, is the average gradient, K is the total number of semantically enhanced images, Enhance images for semantics The corresponding gradient, Enhance images for semantics The corresponding loss value, y is the category label.

5. The method according to claim 1, characterized in that The step of establishing data distribution based on the acquired multiple reference images belonging to the category label comprises: Acquire multiple reference images belonging to the category label; Performing feature extraction based on the multiple reference images to obtain multiple reference deep features; A data distribution is established based on the plurality of reference deep features.

6. The method according to claim 1, characterized in that The step of calculating the updated gradient based on the average gradient includes: The update gradient is calculated based on the average gradient and the update gradient of the previous round by the following formula: In the formula, g t is the updated gradient, μ is the preset momentum factor, g t-1 is the last updated gradient, where the first iteration is g t-1 The value is 0, is the average gradient.

7. The method according to claim 1, characterized in that The updating and cropping of the original image based on the updated gradient to obtain the adversarial image includes: Update the original image based on the updated gradient and the preset step size parameter to obtain an initial adversarial image; The initial adversarial image is cropped based on a preset disturbance threshold to obtain an adversarial image.

8. A device for generating adversarial images based on semantic transformation, characterized in that: include: The first acquisition module is used to acquire the source model, the original image and its corresponding category label; A first establishing module, used for establishing data distribution based on a plurality of reference images obtained and belonging to the category label; A semantic transformation module, used for performing semantic transformation on the original image based on the data distribution to obtain a plurality of semantically enhanced images; A first calculation module, used for inputting the plurality of semantically enhanced images into the source model and calculating an average gradient; A second calculation module, used to calculate an update gradient based on the average gradient; A first updating module, used for updating and cropping the original image based on the updated gradient to obtain an adversarial image; The first judgment module is used to judge whether the preset stop condition is met: if so, an optimized adversarial image is obtained; if not, the process of obtaining the adversarial image is re-executed by the semantic transformation module, the first calculation module, the second calculation module and the first update model.

9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instruction is executed by a processor, the method for generating an adversarial image based on semantic transformation as described in any one of claims 1 to 7 is implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the method for generating an adversarial image based on semantic transformation as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Image augmentation model training method and image classification method based on variational auto-encoder and generative adversarial network

    CN114386534A

  • Artificial intelligence image recognition anti-attack method and system based on gradient average

    CN117079053A