A method and apparatus for generating adversarial images based on semantic transformation
By generating adversarial images through semantic transformation during black-box attacks, the problem of low transferability of adversarial examples in existing technologies is solved, achieving efficient adversarial example generation and enhanced diversity.
Patent Information
- Application Number
- CN202411129020.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2044-08-16
AI Technical Summary
Existing transfer-based black-box attack methods generate adversarial examples with low transferability, and existing input transformation methods cannot change the semantic content of images, thus limiting the diversity and transferability of adversarial examples.
By acquiring the source model, original image, and their category labels, a data distribution is established, semantic transformation is performed to generate multiple semantically enhanced images, the average gradient is calculated, and the images are updated until a preset stopping condition is reached. This optimizes the adversarial images and improves their semantic diversity and transferability.
It improves the efficiency and transferability of adversarial example generation with low computational cost, avoiding the use of high-cost generation models.
Smart Images

Figure CN119048817B_ABST
Abstract
Description
Technical Field
[0001] This invention relates in particular to a method and apparatus for generating adversarial images based on semantic transformation. Background Technology
[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 are widely used in security-critical scenarios such as security monitoring, autonomous driving, facial recognition, and remote sensing. However, research has found that deep neural networks are susceptible to adversarial examples. Adversarial examples introduce deliberately designed small perturbations to cause the model to produce incorrect recognition results. For example, autonomous vehicles may fail to recognize stop signs, or facial recognition systems may be misled, leading to serious consequences.
[0003] Adversarial attacks are categorized into white-box and black-box attacks. In white-box attacks, attackers possess model information and can easily generate adversarial examples by calculating gradients. However, in reality, target models are often proprietary, making it difficult to obtain relevant information. To address this, researchers have developed query- and transfer-based black-box attack methods. Query-based methods are less efficient, while transfer-based methods, by generating adversarial examples on the source model and transferring them to the target model, are more practical and have attracted widespread attention. Attackers can easily attack black-box models with unknown architectures and parameters using transferable adversarial examples, posing a significant threat to many real-world deep neural network-based applications.
[0004] Therefore, studying the transferability of adversarial examples is crucial. It helps identify potential weaknesses in deep neural networks, promotes the development of adversarial defense algorithms, improves model robustness, and provides safeguards for the secure application of artificial intelligence technologies. Strengthening digital security, enhancing national strategic scientific and technological capabilities, and overcoming key core technologies are also essential. Summary of the Invention
[0005] To obtain better adversarial images, this invention provides a method and apparatus for generating adversarial images based on semantic transformation.
[0006] In a first aspect, embodiments of the present invention provide a method for generating adversarial images based on semantic transformation, which may include:
[0007] Obtain the source model, the original image, and their corresponding category labels;
[0008] A data distribution is established based on multiple reference images belonging to the aforementioned category labels;
[0009] Based on the data distribution, the original image is semantically transformed to obtain multiple semantically enhanced images;
[0010] The multiple semantically enhanced images are input into the source model, and the average gradient is calculated.
[0011] The updated gradient is calculated based on the average gradient.
[0012] The original image is updated based on the update gradient and then cropped to obtain an adversarial image;
[0013] Based on the adversarial image, the steps described above—namely, semantic transformation of the adversarial image based on the data distribution to obtain multiple new semantically enhanced images, and obtaining a new adversarial image based on the multiple new semantically enhanced images—are repeated until a preset stopping condition is met, resulting in an optimized adversarial image.
[0014] In one or more optional embodiments of this application, the step of performing semantic transformation on the original image based on the data distribution to obtain multiple semantically enhanced images includes:
[0015] Based on the original image, feature extraction is performed to obtain the original deep features;
[0016] Multiple random samples are performed on the data distribution to obtain multiple semantic transformation directions;
[0017] Based on each semantic transformation direction, the original deep features are transformed to obtain semantically transformed image features;
[0018] Based on the original deep features and the semantically transformed image features, the original image is optimized to obtain a semantically enhanced image.
[0019] In one or more optional embodiments of this application, optimizing the original image based on the original deep features and the semantically transformed image features to obtain a semantically enhanced image includes:
[0020] Based on the original deep features and the semantically transformed image features, the original image is optimized using the following formula to obtain a semantically enhanced image:
[0021]
[0022] In the formula, This represents a semantically enhanced image, where x represents the original image. The total change loss is calculated using the L2 loss. and smoothing loss Composition, where 'a' represents the original deep feature. The image features are after semantic transformation, where smoothing loss... It can be calculated using the following formula:
[0023]
[0024] In the formula, This represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column. This represents the pixel value in the i-th row and j-th column of the semantically enhanced image. This represents the pixel value of the semantically enhanced image in the (i+1)th row and the jth column.
[0025] In one or more optional embodiments of this application, the step of inputting the plurality of semantically enhanced images into the source model and calculating the average gradient includes:
[0026] The multiple semantically enhanced images are input into the source model, and the loss value corresponding to each semantically enhanced image is calculated.
[0027] The gradient corresponding to each semantically enhanced image is calculated based on the loss value corresponding to each semantically enhanced image.
[0028] Based on the gradient corresponding to each semantically enhanced image, the mean is calculated using the following formula to obtain the average gradient:
[0029]
[0030] In the formula, Let K be the average gradient, and K be the total number of semantically enhanced images. semantically enhanced images The corresponding gradient, semantically enhanced images The corresponding loss value, where y is the category label.
[0031] In one or more optional embodiments of this application, establishing a data distribution based on multiple reference images belonging to the category label includes:
[0032] Obtain multiple reference images belonging to the category label;
[0033] Feature extraction is performed based on the multiple reference images to obtain multiple reference deep features;
[0034] A data distribution is established based on the aforementioned multiple reference deep features.
[0035] In one or more optional embodiments of this application, the step of calculating the updated gradient based on the average gradient includes:
[0036] The update gradient is calculated based on the average gradient and the update gradient from the previous round using the following formula:
[0037]
[0038] In the formula, g t To update the gradient, μ is a preset momentum factor, and g t-1 For the previous gradient update, where g is the gradient during the first iteration. t-1 The value is 0. This represents the average gradient.
[0039] In one or more optional embodiments of this application, updating the original image based on the update gradient and cropping it to obtain an adversarial image includes:
[0040] The original image is updated based on the update gradient and the preset step size parameter to obtain the initial adversarial image;
[0041] The initial adversarial image is cropped based on a preset perturbation threshold to obtain an adversarial image.
[0042] Secondly, embodiments of the present invention provide an apparatus for generating adversarial images based on semantic transformation, which may include:
[0043] The first acquisition module is used to acquire the source model, the original image, and their corresponding category labels;
[0044] The first module is used to establish a data distribution based on multiple reference images belonging to the category label.
[0045] A semantic transformation module is used to perform semantic transformation on the original image based on the data distribution to obtain multiple semantically enhanced images;
[0046] The first calculation module is used to input the multiple semantically enhanced images into the source model and calculate the average gradient;
[0047] The second calculation module is used to calculate the updated gradient based on the average gradient.
[0048] The first update module is used to update the original image based on the update gradient and crop it to obtain an adversarial image;
[0049] The first judgment module is used to determine whether the preset stopping condition has been met: if yes, an optimized adversarial image is obtained; if no, the process of obtaining a new adversarial image is re-executed by the semantic transformation module, the first calculation module, the second calculation module, and the first update model.
[0050] Thirdly, embodiments of the present invention provide a computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implements the method for generating adversarial images based on semantic transformation as described above.
[0051] Fourthly, embodiments of the present invention provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the method for generating adversarial images based on semantic transformation as described above.
[0052] Fifthly, embodiments of the present invention provide a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the method for generating adversarial images based on semantic transformation as described above.
[0053] The beneficial effects of the above-described technical solutions provided in the embodiments of the present invention include at least the following:
[0054] This invention provides a method for generating adversarial images based on semantic transformation. The method involves acquiring a source model, an original image, and their corresponding category labels. Based on multiple reference images belonging to the same category labels, a data distribution is established. Semantic transformation is performed on the original image to obtain multiple semantically enhanced images. These enhanced images are then input into the source model to calculate the average gradient, thereby determining the update gradient and obtaining an adversarial image. The process of repeatedly performing semantic transformation on the adversarial image to obtain multiple new semantically enhanced images and new adversarial images continues until a preset stopping condition is met, resulting in an optimized adversarial image. This method performs semantic-level transformations on the image during the iterative optimization process, increasing the diversity of transformed images and thus improving the transferability of the adversarial image. Simultaneously, this method incurs minimal computational cost during semantic transformation, avoiding the use of computationally expensive generation models and effectively improving the generation efficiency of adversarial examples.
[0055] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings.
[0056] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0057] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0058] Figure 1 This is a schematic diagram illustrating the steps of a method for generating adversarial images based on semantic transformation, as provided in an embodiment of the present invention.
[0059] Figure 2 An example schematic diagram illustrating how semantic transformation yields multiple semantically enhanced images, as provided in an embodiment of the present invention.
[0060] Figure 3 A schematic diagram illustrating an example of an adversarial image update method based on semantic transformation provided in an embodiment of the present invention;
[0061] Figure 4 This is a schematic diagram of the structure of the apparatus for generating adversarial images based on semantic transformation provided in an embodiment of this application. Detailed Implementation
[0062] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0063] The inventors discovered that in existing technologies, transfer-based black-box attack methods often overfit the source model, resulting in low transferability of the generated adversarial examples. Therefore, the level of transferability reflects the adversarial example's ability to effectively identify potential vulnerabilities across different models. In recent years, researchers have proposed numerous adversarial attack methods to improve the transferability of adversarial examples. Studies have found that the higher the diversity of the transformed image, the higher the transferability of the adversarial example. However, most existing input transformation methods use simple spatial transformation strategies, such as random resizing, translation, and mixing of different images. While these transformation techniques can effectively improve the transferability of adversarial examples, they only change the spatial structure of the image but cannot alter the semantic content of the original image, such as the color, pose, and angle of the background or foreground objects. This limits the diversity of the transformed image, leading to limited transferability.
[0064] Based on this, the inventors conducted further research and development and came up with this invention, which provides a method and apparatus for generating adversarial images based on semantic transformation.
[0065] Example 1
[0066] Embodiment 1 of this invention provides a method for generating adversarial images based on semantic transformation, referring to... Figure 1 As shown, the method may include the following steps S101-S108:
[0067] S101: Obtain the source model, the original image, and its corresponding category label.
[0068] S102: Establish a data distribution based on multiple reference images belonging to the category labels.
[0069] S103: Based on the data distribution, perform semantic transformation 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: The updated gradient is calculated based on the average gradient.
[0072] S106: Update the original image based on the update gradient and crop it to obtain the adversarial image.
[0073] S107: Determine whether the preset stopping condition has been met: If yes, proceed to step S108; if no, re-execute steps S103-S106 based on the adversarial image.
[0074] S108: Obtain the optimized adversarial image.
[0075] This invention provides a method for generating adversarial images based on semantic transformation. The method involves acquiring a source model, an original image, and their corresponding category labels. Based on multiple reference images belonging to the same category labels, a data distribution is established. Semantic transformation is performed on the original image to obtain multiple semantically enhanced images. These enhanced images are then input into the source model to calculate the average gradient, thereby determining the update gradient and obtaining an adversarial image. The process of repeatedly performing semantic transformation on the adversarial image to obtain multiple new semantically enhanced images and new adversarial images continues until a preset stopping condition is met, resulting in an optimized adversarial image. This method performs semantic-level transformations on the image during the iterative optimization process, increasing the diversity of transformed images and thus improving the transferability of the adversarial image. Simultaneously, this method incurs minimal computational cost during semantic transformation, avoiding the use of computationally expensive generation models and effectively improving the generation efficiency of adversarial examples.
[0076] Let us first discuss the technical problems that need to be solved in this field:
[0077] Given an original image x and its corresponding class label y, we obtain a 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 , to make the adversarial image x adv The source model f() is tricked so that its predicted output is not equal to y, i.e., f(x) adv )≠y.
[0078] Meanwhile, the adversarial image contains only a tiny perturbation relative to the original image. This perturbation is sufficient to cause deep learning models (such as neural networks) to produce incorrect predictions or classifications, but it is almost imperceptible to human observers. In this field, this perturbation is called an adversarial perturbation, and L0 is used. pNorm measures the magnitude of adversarial perturbations, using a preset perturbation threshold ∈ to achieve imperceptibility to the perturbation, i.e., ||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 Equation 1 below:
[0079]
[0080] In the formula, J(x) adv ,y) represents the classification loss function of the source model.
[0081] To solve the optimization problem shown in Equation 1 above, it is necessary to calculate the gradient of the classification loss function relative to the input image. However, using only the gradient from a single image to update adversarial examples easily leads to overfitting to the source model f(), resulting in poor transferability. To improve the transferability of adversarial examples, some studies have proposed adversarial example generation methods based on input transformation. This method involves transforming the image before calculating the gradient and using the gradients from multiple transformed images to update the adversarial examples, effectively alleviating the overfitting of adversarial examples to the source model and is one of the most effective methods to improve transferability. However, most existing input transformation methods use simple spatial transformations, only changing the spatial structure of the image but failing to change the semantic content of the original image. This limits the diversity of transformed images, resulting in limited transferability. Therefore, this invention proposes a method for generating adversarial images based on semantic transformation.
[0082] The specific implementation steps of this application will be explained step by step below:
[0083] In step S101 above, 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 step S102 above, a data distribution is established based on the multiple reference images belonging to the category labels. Specifically, this includes the following steps S1021-S1023:
[0085] S1021: Obtain multiple reference images belonging to the category label.
[0086] Specifically, it could be to collect N reference images {x1, x2, x3, ..., x...} belonging to the category label y. N For example, collect 1000 reference images with the category label y being "bird".
[0087] S1022: Feature extraction is performed based on multiple reference images to obtain multiple reference deep features.
[0088] Specifically, it could be that N reference images {x1,x2,x3,...,x...} are used. N The inputs are respectively fed into the feature extraction model to obtain N reference deep features {a1, a2, a3, ..., a N The feature extraction model can utilize open-source models from the image domain, such as VGGNet and ViT.
[0089] In one specific embodiment, VGGNet is used as a feature extraction model. The specific steps of inputting the reference image into the feature extraction model to obtain reference deep features include: loading a pre-trained VGGNet from the PyTorch model library, removing the last fully connected layer of VGGNet, retaining the convolutional layers for extracting deep features, and then inputting the reference image into the processed VGGNet to obtain 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 {a1,a2,a3,...,a...} N Calculate the covariance, and then establish a data distribution based on the covariance. This data distribution can be a zero-mean multivariate normal distribution N(0,Σy).
[0092] The covariance is calculated using the following formula 2:
[0093]
[0094] In the formula, ∑y represents the covariance of the reference deep features with category label y, and x j Let be the j-th reference deep feature, and μ be the mean of all reference deep features.
[0095] Of course, in some other embodiments, the data distribution can also take other forms, such as a multivariate normal distribution with a non-zero mean.
[0096] In this embodiment, feature extraction is performed based on multiple reference images, and a data distribution is established. The mean of the data distribution represents the commonalities of images with the same category label, and the covariance represents the range of semantic variations (color, shape, pose, etc.) of the images with that category label, or in other words, the feature distribution. This makes the data distribution contain rich latent semantic transformation information. Therefore, for images with the same category label, the effective direction of semantic transformation can be well represented by the data distribution.
[0097] In this context, a valid semantic transformation direction means that the category label of the image remains unchanged before and after the semantic transformation. Since the goal in this field is to mislead the source model or the target attack model to produce incorrect classification results, the gradient direction of the source model for the input image should point from the original class to another class, for example, from "bird" to "cat". However, if the category label of the image changes before the attack, the gradient direction of the source model will become from one class to another, for example, from "cat" to "cat", which is unrelated to the original image's category label "bird". This results in an inaccurate gradient direction, which affects the success rate of adversarial examples and leads to reduced transferability. Therefore, semantic transformations should not change the image's category label; that is, a bird in the original image should not be converted to an object of another category such as a car or airplane.
[0098] In step S103 above, multiple random samples are performed based on the data distribution, and semantic transformation is applied to the original image to obtain multiple semantically enhanced images. Specifically, this includes the following steps S1031-S1034:
[0099] S1031: Extract features from the original image to obtain the original deep features.
[0100] Specifically, the original image x can be input into a feature extraction model to obtain the original deep features a. The feature extraction model can be an open-source model from the image domain, such as VGGNet or ViT. The specific steps for feature extraction using the feature extraction model have been explained in step S1022 above and will not be repeated here.
[0101] S1032: Perform multiple random samplings on the data distribution to obtain multiple semantic transformation directions.
[0102] Specifically, this could involve performing a random sampling on the data distribution to obtain a semantic transformation direction w ~ N(0, Σy), and repeating this random sampling K times to obtain K semantic transformation directions. Where K is a positive integer, for example, it can be set to 20.
[0103] S1033: Based on each semantic transformation direction, transform the original deep features to obtain the semantically transformed image features.
[0104] Specifically, it could be based on each semantic transformation direction w k Based on the following formula 3, the original deep features are interpolated to obtain the semantically transformed image features.
[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 based on the original deep features and the semantically transformed image features to obtain a semantically enhanced image.
[0108] Specifically, it can be based on the original deep feature 'a' and the semantically transformed image features. The semantically enhanced image is obtained by optimizing the original image x using the following formula 4.
[0109]
[0110] In the formula, This represents a semantically enhanced image, where x represents the original image. The total change loss is calculated using the L2 loss. and smoothing loss Composition, where 'a' represents the original deep feature. The image features are after semantic transformation, where smoothing loss... It can be calculated using the following formula:
[0111]
[0112] In the formula, This represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column. This represents the pixel value in the i-th row and j-th column of the semantically enhanced image. This represents the pixel value of the semantically enhanced image in the (i+1)th row and the jth column.
[0113] In this embodiment, effective semantic transformation directions are obtained by sampling the data distribution, and feature interpolation is performed to obtain semantically transformed features. These features are then used to optimize the pixels of the original image, aligning the features of the original image with the semantically transformed features to obtain a semantically enhanced image. This method incurs minimal computational cost during feature interpolation and does not require the manual annotation of the dataset and the training of an expensive generative model, as is common in conventional image semantic transformation methods. Existing technologies use manual annotation methods, collecting images with different semantic content and assigning multiple semantic labels to different semantic directions. For example, for human images, different semantic labels could include wearing glasses, having a beard, or different hair colors. The mean of the image features with different semantic labels is then calculated to obtain different semantic transformation directions. However, this process requires extensive manual image collection and annotation, and manual annotation alone cannot exhaustively cover all semantic directions of different object categories. This method avoids the huge manual costs associated with collecting different semantic images and labels, effectively improving the efficiency of adversarial example generation.
[0114] To facilitate understanding of this solution by those skilled in the art, the specific implementation of step S103 provided in the embodiments of this application is described more clearly and completely below by way of example, referring to... Figure 2 As shown, the execution order of step S103 is from left to right. The dotted box on the left represents the deep features of multiple categories labeled "bird" in the feature space. By calculating the intra-class covariance, a data distribution is established, multiple semantic transformation directions are sampled, and semantic transformation is performed to obtain the three semantically enhanced images on the right. 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 effective semantic transformation.
[0115] In step S104 above, multiple semantically enhanced images are input into the source model, and the average gradient is calculated. Specifically, this 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, it can be that the K semantically enhanced images obtained in step S103 above are... Input the source model f(), and then calculate the loss value corresponding to each semantically enhanced image based on the loss function in the source model f(). For example, when the loss function in the source model is the cross-entropy loss function, then the semantically enhanced image... The corresponding loss value is calculated using Formula 6 below:
[0118]
[0119] In the formula, semantically enhanced images The corresponding loss value, Predict semantically enhanced images for the source model The probability of belonging to category label y.
[0120] S1042: Calculate the gradient corresponding to each semantically enhanced image based on the loss value corresponding to each semantically enhanced image.
[0121] Specifically, it could be based on semantically enhanced images. The corresponding gradient is calculated from the corresponding loss value. Those skilled in the art can calculate the gradient based on the loss value using detailed descriptions of existing technologies, such as the `backward()` function in the PyTorch deep learning framework.
[0122] S1043: Based on the gradient corresponding to each semantically enhanced image, calculate the mean using the following formula 7 to obtain the average gradient:
[0123]
[0124] In the formula, Let K be the average gradient, and K be the total number of semantically enhanced images. semantically enhanced images The corresponding gradient, semantically enhanced images The corresponding loss value is y, where y is the class label and t represents the iteration round.
[0125] In step S105 above, the updated gradient is calculated based on the average gradient. Specifically, the updated gradient can be calculated using the following formula 8 based on the average gradient and the updated gradient from the previous round:
[0126]
[0127] In the formula, g t To update the gradient, μ is a preset momentum factor, and g t-1 For the previous gradient update, where g is the gradient during the first iteration. t-1 The value is 0. Let t be the average gradient and t represent the iteration round.
[0128] In step S106 above, the original image is updated based on the update gradient and cropped to obtain the adversarial image, specifically including the following steps S1061-S1062:
[0129] S1061: Based on the updated gradient and preset step size parameters, the original image is updated using the following formula 9 to obtain the initial adversarial image:
[0130]
[0131] In the formula, For the initial adversarial image, Let g be the previous adversarial image, where g 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 update gradient g. t The direction of t represents the iteration round.
[0132] S1062: Based on a preset perturbation threshold, the initial adversarial image is cropped using the following formula 10 to obtain the adversarial image:
[0133]
[0134] In the formula, For the adversarial image, clip{} is a clipping function used to clip the initial adversarial image. The data is restricted to a specified range [x, ∈], where ∈ is a preset perturbation threshold used to limit the size of the perturbation and achieve imperceptibility of the perturbation, and t represents the iteration round.
[0135] To facilitate understanding of this solution by those skilled in the art, the specific implementation of steps S103-S106 provided in the embodiments of this application is described more clearly and completely below by way of example, referring to... Figure 3 As shown, from left to right, the execution order of steps S103-S106 is as follows: the input image is semantically transformed to obtain K transformed images, which are then input into the classification model to calculate the gradient. The input image is updated based on the gradient to obtain adversarial examples. 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 step S107 above, determining that the preset stop condition has been met specifically includes the following steps S1071-S1073:
[0137] S1071: Determine whether the preset stop condition has been met: if yes, proceed to step S1072; if no, proceed to step S1073.
[0138] S1072: Returns the adversarial image obtained in the latest iteration round.
[0139] S1073: Adversarial image obtained based on the current iteration round Repeat steps S103-S106 above to perform adversarial image based on data distribution. Semantic transformation is performed to obtain multiple new semantically enhanced images, and a new adversarial image is obtained based on these multiple new semantically enhanced images. The steps.
[0140] The preset stopping condition can be set to reach a fixed number of iterations, or the adversarial image transferability reaches a threshold, etc. No specific limitations are required here.
[0141] Example 2
[0142] Based on the same inventive concept, embodiments of the present invention also provide an apparatus for generating adversarial images based on semantic transformation, referring to... Figure 4 As shown, the device includes:
[0143] The first acquisition module is used to acquire the source model, the original image, and their corresponding category labels;
[0144] The first module is used to establish a data distribution based on multiple reference images belonging to the category label.
[0145] A semantic transformation module is used to perform semantic transformation on the original image based on the data distribution to obtain multiple semantically enhanced images;
[0146] The first calculation module is used to input the multiple semantically enhanced images into the source model and calculate the average gradient;
[0147] The second calculation module is used to calculate the updated gradient based on the average gradient.
[0148] The first update module is used to update the original image based on the update gradient and crop it to obtain an adversarial image;
[0149] The first judgment module is used to determine whether the preset stopping condition has been met: if yes, an optimized adversarial image is obtained; if no, the process of obtaining a new adversarial image is re-executed by the semantic transformation module, the first calculation module, the second calculation module, and the first update model.
[0150] Example 3
[0151] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium storing a computer program / instructions thereon, which, when executed by a processor, implements the method for generating adversarial images based on semantic transformation as described in Embodiment 1 above.
[0152] Example 4
[0153] Based on the same inventive concept, embodiments of the present invention also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the method for generating adversarial images based on semantic transformation as described in Embodiment 1 above.
[0154] Example 5
[0155] Based on the same inventive concept, embodiments of the present invention also provide a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the method for generating adversarial images based on semantic transformation as described in Embodiment 1 above.
[0156] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.
[0157] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0158] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0159] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0160] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for generating adversarial images based on semantic transformation, characterized in that, include: Obtain the source model, the original image, and their corresponding category labels; A data distribution is established based on multiple reference images belonging to the aforementioned category labels; Based on the data distribution, the original image is semantically transformed to obtain multiple semantically enhanced images; The multiple semantically enhanced images are input into the source model, and the average gradient is calculated. The update gradient is calculated based on the average gradient and the update gradient from the previous round using the following formula: ; In the formula, To update the gradient, To preset the momentum factor, For the previous update gradient, where in the first iteration... The value is 0. The average gradient; The original image is updated based on the update gradient and then cropped to obtain an adversarial image; Based on the adversarial image, the steps described above, namely, performing semantic transformation on the adversarial image based on the data distribution to obtain multiple new semantically enhanced images, and obtaining a new adversarial image based on the multiple new semantically enhanced images, are repeated until a preset stopping condition is reached to obtain an optimized adversarial image. The original image is semantically transformed to obtain multiple semantically enhanced images, including: Based on the original image, feature extraction is performed to obtain the original deep features; Multiple random samples are performed on the data distribution to obtain multiple semantic transformation directions; Based on each semantic transformation direction, the original deep features are transformed to obtain semantically transformed image features; Based on the original deep features and the semantically transformed image features, the original image is optimized using the following formula to obtain a semantically enhanced image: ; In the formula, Represents semantically enhanced images. Represents the original image. The total change loss is calculated using the L2 loss. and smoothing loss composition, For original deep features, The image features are after semantic transformation, where smoothing loss... It can be calculated using the following formula: ; In the formula, This represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column. This represents the pixel value in the i-th row and j-th column of the semantically enhanced image. This represents the pixel value of the semantically enhanced image in the (i+1)th row and the jth column.
2. The method according to claim 1, characterized in that, The step of inputting the multiple semantically enhanced images into the source model and calculating the average gradient includes: The multiple semantically enhanced images are input into the source model, and the loss value corresponding to each semantically enhanced image is calculated. The gradient corresponding to each semantically enhanced image is calculated based on the loss value corresponding to each semantically enhanced image. Based on the gradient corresponding to each semantically enhanced image, the mean is calculated using the following formula to obtain the average gradient: ; In the formula, Let K be the average gradient, and K be the total number of semantically enhanced images. semantically enhanced images The corresponding gradient, semantically enhanced images The corresponding loss value, For category labels.
3. The method according to claim 1, characterized in that, The step of establishing a data distribution based on multiple reference images belonging to the acquired category label includes: Obtain multiple reference images belonging to the category label; Feature extraction is performed based on the multiple reference images to obtain multiple reference deep features; A data distribution is established based on the aforementioned multiple reference deep features.
4. The method according to claim 3, characterized in that, The feature extraction based on the multiple reference images yields multiple reference deep features, including: The multiple reference images are input into the feature extraction model to obtain multiple reference deep features; The feature extraction model is VGGNet, and the method further includes: removing the last fully connected layer of the VGGNet and retaining the convolutional layers for extracting deep features.
5. The method according to claim 3, characterized in that, The establishment of a data distribution based on the multiple reference deep features includes: Calculate the covariance based on the multiple reference deep features; A zero-mean multivariate normal distribution is established based on the covariance.
6. The method according to claim 1, characterized in that, The step of updating the original image based on the update gradient and cropping it to obtain an adversarial image includes: The original image is updated based on the update gradient and the preset step size parameter to obtain the initial adversarial image; The initial adversarial image is cropped based on a preset perturbation threshold to obtain an adversarial image.
7. An apparatus 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 their corresponding category labels; The first module is used to establish a data distribution based on multiple reference images belonging to the category label. A semantic transformation module is used to perform semantic transformation on the original image based on the data distribution to obtain multiple semantically enhanced images; Specifically, the semantic transformation module is used for: Based on the original image, feature extraction is performed to obtain the original deep features; Multiple random samples are performed on the data distribution to obtain multiple semantic transformation directions; Based on each semantic transformation direction, the original deep features are transformed to obtain semantically transformed image features; Based on the original deep features and the semantically transformed image features, the original image is optimized using the following formula to obtain a semantically enhanced image: ; In the formula, Represents semantically enhanced images. Represents the original image. The total change loss is calculated using the L2 loss. and smoothing loss composition, For original deep features, The image features are after semantic transformation, where smoothing loss... It can be calculated using the following formula: ; In the formula, This represents the pixel value of the semantically enhanced image in the i-th row and j+1-th column. This represents the pixel value in the i-th row and j-th column of the semantically enhanced image. This represents the pixel value in the (i+1)th row and jth column of the semantically enhanced image; The first calculation module is used to input the multiple semantically enhanced images into the source model and calculate the average gradient; The second calculation module is used to calculate the updated gradient based on the average gradient, including calculating the updated gradient based on the average gradient and the updated gradient of the previous round using the following formula: ; In the formula, To update the gradient, To preset the momentum factor, For the previous update gradient, where in the first iteration... The value is 0. The average gradient; The first update module is used to update the original image based on the update gradient and crop it to obtain an adversarial image; The first judgment module is used to re-execute the steps of semantic transformation of the adversarial image based on the data distribution to obtain multiple new semantically enhanced images, and to obtain a new adversarial image based on the multiple new semantically enhanced images, until a preset stopping condition is reached to obtain an optimized adversarial image. Specifically, it is used to: determine whether the preset stopping condition has been reached; if yes, obtain the optimized adversarial image; if no, re-execute the process of obtaining the adversarial image by the semantic transformation module, the first calculation module, the second calculation module and the first update model.
8. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When executed by a processor, the computer program / instruction implements the method for generating adversarial images based on semantic transformation as described in any one of claims 1-6.
9. A computer program product comprising a computer program / instructions, characterized in that, When executed by a processor, the computer program / instruction implements the method for generating adversarial images based on semantic transformation as described in any one of claims 1-6.
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
