Adversarial patch generation method and device

By combining the detection model output loss and feature map in aerial image processing to optimize the adversarial patch, the problem that the adversarial patch generation method in the existing technology is limited to a specific network architecture is solved, and a more versatile and efficient adversarial patch generation is achieved. Improved generalization and transfer performance.

CN118537857APending Publication Date: 2024-08-23启元实验室
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410338569.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-22
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Existing adversarial patch generation methods are limited by specific detection network architectures and cannot be applied to all detection networks. Moreover, adversarial patches have poor generalization performance and transferability, and cannot effectively deceive different detection models.

Method used

By collecting aerial images, marking the target to be attacked, training the target detection perception model, generating adversarial patches, and using backpropagation to optimize the patches, combined with the output loss and feature map of the detection model, a more general adversarial patch generation method is designed, taking into account the aerial photography perspective Enhance the robustness of the patch against weather changes, motion blur and other factors.

Benefits of technology

It achieves more general adversarial patch generation, improves the generalization performance and migration performance of patches, makes the generated patches have better adversarial effects on different detection models, and enhances the robustness and black-box migration performance of adversarial patches.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118537857A
    Figure CN118537857A
Patent Text Reader

Abstract

The invention provides an adversarial patch generation method and device, relates to the technical field of graphic image processing, solves the problems that in the prior art, adversarial patches are low in universality and poor in generalization performance, and adopts the scheme that aerial images are collected, a to-be-attacked target is marked, a target detection perception model is trained, and the adversarial patches are generated. Respectively inputting the image pasted with the adversarial patch and the image not pasted with the adversarial patch into a detection model for detection to obtain an adversarial patch image feature map and a non-patch image feature map; calculating the feature map output by the anti-patch image feature map and the feature map output by the non-patch image feature map, and combining the output loss of the detection model to obtain an anti-patch target loss function; and calculating a gradient value according to the target loss function, and after back propagation, updating the pixel value of the adversarial patch to complete optimization of the adversarial patch. According to the scheme of the invention, the design of a loss function according to a network structure is not needed, and the method is a more universal adversarial patch with higher generalization performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of graphics and image processing, and in particular to a method and device for generating an adversarial patch. Background Art

[0002] This section is intended to provide background or context for the embodiments of the invention set forth in the claims. The descriptions herein may include concepts that may be explored, but not necessarily concepts that have been previously thought of or explored. Therefore, unless otherwise noted herein, the content described in this section is not prior art with respect to the specification and claims of this application, and is not admitted to be prior art by inclusion in this section.

[0003] In the field of optical remote sensing, target detection technology based on DNNs has shown excellent performance. However, studies have found that DNNs are vulnerable to attacks by adversarial samples carefully designed by humans, resulting in detection errors, which hinders the deployment and application of intelligent detection algorithms. Research on adversarial texture generation technology can enable important targets to evade the detection of detectors on the one hand, and on the other hand, it can explore the loopholes of detectors, improve the robustness of detectors and the reliability of target detection results.

[0004] The adversarial attack method based on adversarial patches generates patches with specific textures and pastes them on the target to deceive the target detector, making it unable to accurately perceive the target.

[0005] At present, adversarial patches are mainly obtained by attacking the target detector's target confidence loss or classification loss through back-propagation iterative optimization. This method is limited to a specific detection network architecture and is not applicable to all detection networks. The loss function used to generate adversarial patches needs to be adjusted according to the detection network, which is relatively complicated.

[0006] Therefore, how to achieve a more general adversarial patch with stronger generalization performance is a technical problem that needs to be solved. Summary of the invention

[0007] In order to solve the above-mentioned technical problems, the present invention provides a method and device for generating an anti-patch.

[0008] To solve the above technical problems, in a first aspect, according to some embodiments, the present invention provides a method for generating an adversarial patch.

[0009] Collect aerial images and annotate the targets to be attacked, train the target detection perception model, and generate adversarial patches;

[0010] Inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection respectively, and obtaining the adversarial patch image feature map and the non-patch image feature map respectively;

[0011] Calculating the feature maps outputted from the feature map of the adversarial patch image and the feature map of the non-patch image, and combining the output loss of the detection model to obtain a target loss function of the adversarial patch;

[0012] The gradient value is calculated according to the target loss function, and after back propagation, the pixel value of the adversarial patch is updated to complete the optimization of the adversarial patch.

[0013] In some embodiments, generating the adversarial patch specifically includes:

[0014] Marking the rotating frame of the target to be attacked according to the collected aerial image;

[0015] According to the detection category of the target to be attacked and the scale of the aerial image, the shape and size of the initial adversarial patch are set, and the gradient information of the initial adversarial patch is retained;

[0016] The image is read, the image data and the coordinates of the marked box of the target to be attacked are obtained, the marked box is processed, and the adversarial patch is generated.

[0017] In some embodiments, retaining the gradient information of the initial adversarial patch specifically includes:

[0018] The value of the attribute required_grad of the initial adversarial patch is set to true, and the initial adversarial patch is passed to the optimizer object, so that the adversarial patch can update parameters according to the gradient value obtained by back propagation.

[0019] In some embodiments, the processing of the annotation box specifically includes:

[0020] The detection format of the target is YOLO format (x c ,y c ,w,h,angle), where x c ,y c ,w,h is used to determine the position of the target to be attacked, and angle determines the rotation direction of the target;

[0021] The detection frame information of the target to be attacked is normalized so that the value is within the range of [0, 1].

[0022] In some embodiments, reading the image specifically includes:

[0023] The read images have multiple batches, the batch size is B, and the image data dimension of each batch is (B×C×H×W);

[0024] Among them, H is the image height, W is the image width, and C is the number of image channels.

[0025] In some embodiments, the normalizing the detection frame information of the target to be attacked specifically includes:

[0026] The detection format of the target is YOLO format (x c ,y c ,w,h,angle), use the following formulas 1, 2, 3, and 4 to normalize the target detection frame coordinates to obtain the normalized annotation frame information (x c ′ ,y c ′ ,w ′ ,h ′ ,angle);

[0027] Among them, formula 1 is as follows:

[0028]

[0029] Formula 2 is as follows:

[0030]

[0031] Formula 3 is as follows:

[0032]

[0033] Formula 4 is as follows:

[0034]

[0035] In some embodiments, after generating the adversarial patch and before respectively inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, the method further includes:

[0036] Performing EOT transformation on the generated adversarial patch;

[0037] Performing an affine transformation on the adversarial patch;

[0038] The adversarial patch is placed at the target to be attacked in the original image size, and the patch is attached to the target to be attacked by replacing pixels.

[0039] In some embodiments, performing EOT transformation on the generated adversarial patch specifically includes:

[0040] Performing median filtering preprocessing on the adversarial patch;

[0041] The number of patches after the preprocessing is expanded to a preset maximum number of attack targets;

[0042] Performing image enhancement transformation on the expanded adversarial patch;

[0043] The image enhancement transformation includes at least one of the spatial level transformations such as random addition of noise, contrast, brightness, motion blur, weather change pixel level transformation, random flipping, etc.

[0044] In some embodiments, performing an affine transformation on the adversarial patch specifically includes:

[0045] Expanding the number of patches transformed by the EOT to a preset maximum number of attack targets;

[0046] According to the position of the target to be attacked in the image, the patch is scaled and rotated to the image attack target by using affine transformation to fit the target.

[0047] In some embodiments, the image enhancement transformation specifically includes:

[0048] A transformation probability parameter P is provided for adjusting the probability of each of the image enhancement transformations;

[0049] The image enhancement transformation is performed using the following formula 5:

[0050] P′=EOT(P) (5)

[0051] Wherein, P′ is the transformed patch, and EOT() represents the EOT image enhancement processing performed on the adversarial patch.

[0052] In some embodiments, the step of expanding the number of patches that have undergone the image enhancement transformation to a preset maximum number of attack targets specifically includes:

[0053] Determining the number of attack targets for each image according to the labels of the targets to be attacked;

[0054] Create a Mask matrix tensor G′ with the same dimension as the adversarial patch tensor, where the Mask matrix tensor is used to identify the attack target, marking the position where the attack target exists as 1 and marking the other positions as 0;

[0055] The matrix tensor G′ and the adversarial patch P′ are padded to the same shape as the input image.

[0056] In some embodiments, filling the matrix tensor G′ and the adversarial patch P′ into a shape having the same size as the input image specifically includes:

[0057] Output the matrix tensor G′, and paste the adversarial patch to the target to be attacked, wherein the positions of 0 in the matrix tensor adopt the pixel values ​​of the clean image, and the positions of non-0 adopt the pixel values ​​of the adversarial patch.

[0058] In some embodiments, the affine transformation specifically includes:

[0059] The affine transformation process adopts Formula 6, as follows:

[0060]

[0061] Among them, x, y are the coordinates before affine transformation, x′, y′ are the coordinates after affine transformation, the first two columns are used to set the rotation angle θ and the scaling ratio scale to achieve rotation and scaling, and the third column is used to achieve image translation.

[0062] In some embodiments, placing the adversarial patch at the target to be attacked at the original image size specifically includes:

[0063] According to the label information of the target to be attacked, resample the adversarial patch P′ to the target to be attacked;

[0064] Multiply the adversarial patch matrix tensor P′ by the matrix tensor G′ to obtain the output matrix P E ;

[0065] The output matrix P E The obtained adversarial patch is pasted to the position of the target to be attacked.

[0066] In some embodiments, the output matrix P E , obtained using Formula 7, as follows:

[0067] P E =P′*G′ (7)

[0068] Among them, the output matrix P E , the pixel value at the patch of the target to be attacked is not 0, and the other pixel values ​​are 0.

[0069] In some embodiments, the output matrix P E The obtained adversarial patch is pasted to the position of the target to be attacked, specifically including:

[0070] The output matrix P E The positions of the tensor that are 0 use the pixel values ​​of the clean image, and the positions that are not 0 use the output matrix P E Generate the adversarial patch according to the pixel value at the corresponding index;

[0071] Paste the countermeasure patch to the position of the target to be attacked;

[0072] Among them, the image tensor I of the adversarial patch p , the dimension is the same as the dimension of the image data in each batch.

[0073] In some embodiments, before inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, the method further includes:

[0074] According to the labeling information of the target to be attacked, the image with the adversarial patch and the image without the adversarial patch are processed separately to generate a Mask tensor that only displays the target to be attacked.

[0075] In some embodiments, the step of inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection to obtain the adversarial patch image feature map and the non-patch image feature map, respectively, specifically includes:

[0076] The image with the adversarial patch and the image without the adversarial patch are respectively input into the target detection model for detection, and the feature maps passing through the backbone network and the neck network are respectively obtained, and the feature map of the adversarial anti-patch image and the feature map of the non-patch image are extracted.

[0077] In some embodiments, the processing of the image with the adversarial patch and the image without the adversarial patch separately includes:

[0078] Obtaining position information of the target detection frame according to the position of the target in the original image;

[0079] Initialize the Mask tensor T and set all of them to 0, fill the pixels at the position of the target in the target detection frame with 1 according to the position of the target in the image, and obtain a binary Mask tensor T′ that only displays the target to be attacked;

[0080] The output tensor I of the image of the adversarial patch p , multiplied by the tensor T′ that only displays the attack target, so that the pixel values ​​of the image other than the target to be attacked are all set to 0, only the pixels at the target are displayed, and the target to be attacked has a patch;

[0081] The non-patch clean image tensor I is multiplied by the tensor T′ that only displays the attack target, so that the pixel values ​​of the image other than the attack target are all set to 0, and only the pixels at the attack target are displayed, and the attack target does not have an adversarial patch.

[0082] In some embodiments, the multiplication of the non-patch clean image tensor I and the tensor T′ showing only the attack target specifically includes:

[0083] Formula 8 is used to multiply the non-patch clean image tensor I by the tensor T′ showing only the attack target. The formula 8 is as follows:

[0084] I′=I*T′ (8).

[0085] In some embodiments, the output tensor I of the image of the adversarial patch p , multiplied by the tensor T′ that only displays the attack target, specifically including:

[0086] Formula 9 is used to multiply the non-patch clean image tensor I by the tensor T′ showing only the attack target. The formula 9 is as follows:

[0087] I p ′=I p *T′ (9).

[0088] In some embodiments, the calculating of the feature maps outputted from the adversarial patch image feature map and the non-patch image feature map and combining the output loss of the detection model to obtain the target loss function of the adversarial patch specifically includes:

[0089] The feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network p , subtract according to the corresponding layer, and map the output value to the interval [0, 1], add the classification loss or target loss in the output loss of the detection model, negate it and add 1, as the target loss function of the adversarial patch.

[0090] In some embodiments, the feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network p , subtract according to the corresponding layer, including:

[0091] Formula 10 is used to convert the feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the neck network with the adversarial patch image p , subtract according to the corresponding layer, using the formula 10, as follows:

[0092] R(i)=F(i)-F p (i), i = 1, 2, ... L (10)

[0093] Among them, i represents the feature map of the i-th layer, and the number of feature maps is L.

[0094] In some embodiments, the loss function of the i-th layer feature map is obtained by:

[0095] Formula 11 is used to calculate the loss function of the feature map of the i-th layer, as follows:

[0096]

[0097] Among them, L feature (i) represents the feature map loss of the i-th layer, Abs() represents the absolute value function, and sum() represents the sum function. sum(R(i)≠0) represents the sum of the number of non-zero elements in R(i).

[0098] In some embodiments, mapping the output value to the interval [0, 1] specifically includes:

[0099] The loss function L of each layer feature map will be calculated feature (i) Sum and use the sigmoid function to map it to the interval [0, 1] to obtain the attack loss L attack , as shown in Formula 12:

[0100]

[0101] The calculation process of the sigmoid() function is shown in Formula 13:

[0102]

[0103] In some embodiments, mapping the output value to the interval [0, 1], adding the classification loss or target loss in the output loss of the detection model, negating it and adding 1, as the target loss function of the adversarial patch, specifically includes:

[0104] The objective loss function L of the adversarial patch adv , determined using Formula 14:

[0105] L adv =1-aL attack +β*L cls / object (14)

[0106] Where α and β are adjustment coefficients used to make the value of the target loss function of the adversarial patch within a reasonable range, L attack represents the attack loss obtained by mapping the output value to the interval [0, 1], L cls represents the classification loss of the detection model, L object Represents the target confidence loss.

[0107] In a second aspect, an embodiment of the present invention further provides a device for generating a countermeasure patch, comprising:

[0108] The generation module is used to collect aerial images and annotate the targets to be attacked, train the target detection perception model, and generate adversarial patches;

[0109] The optimization module is used to input the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, respectively, to obtain the adversarial patch image feature map and the non-patch image feature map; it is also used to calculate the feature maps output by the adversarial patch image feature map and the non-patch image feature map, and combine the output loss of the detection model to obtain the target loss function of the adversarial patch; it is also used to calculate the gradient value according to the target loss function, update the pixel value of the adversarial patch after back propagation, and complete the optimization of the adversarial patch.

[0110] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods described in the first aspect when executing the program.

[0111] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods described in the first aspect above.

[0112] The above technical solution of the present invention has at least the following beneficial technical effects: the technical solution of the embodiment of the present invention, after generating the initial adversarial patch, respectively inputs the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, respectively obtains the adversarial patch image feature map and the non-patch image feature map, then calculates the feature map output by the adversarial patch image feature map and the non-patch image feature map, and combines the output loss of the detection model to obtain the target loss function of the adversarial patch, which has a better target stealth effect. The technical solution of the embodiment of the present invention is the first adversarial texture generation method under the aerial perspective based on the suppression of key feature regions, and can also be understood as a physical stealth attack method based on the suppression of key feature regions, which not only considers the loss of the detection model output, but also considers the influence of the patch on the feature map, maximizes the difference between the patched and non-patched images in the detection model output tensor, can make the optimized generated patch have a more generalized attack effect, and at the same time enhances the black box migration performance of the patch, so that the patch still has a good adversarial effect on different detection models. The technical solution of the present invention is the first adversarial texture generation algorithm under aerial perspective based on suppression of key feature areas. In the prior art, the solution is obtained by attacking the target confidence loss or classification loss of the target detector and optimizing iteratively through back propagation. The method of the prior art is limited to a specific detection network architecture and is not applicable to all detection networks. The loss function for generating adversarial patches needs to be adjusted according to the detection network, which is relatively complicated. Therefore, the adversarial patch generation method of the prior art solution has the problem of poor transferability. The solution of the present invention combines the detector output loss with the target detection network output feature layer in the design of the attack target function, thereby improving the generalization of the adversarial patch. The feature map-based method can improve the generalization performance of the patch attack on the one hand, and can also be applied to a variety of detection models as a general method on the other hand, without the need to design the loss function according to the network structure. It is a more general adversarial patch with stronger generalization performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0113] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the conventional technology, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0114] Figure 1 This is a flow chart of a method for generating an adversarial patch provided by an embodiment of the present invention.

[0115] Figure 2 It is a detailed process flow chart of a method for generating an anti-patch provided by an embodiment of the present invention.

[0116] Figure 3 It is a patch image compared after being transformed with different EOTs, provided by an embodiment of the present invention.

[0117] Figure 4 This is a comparison image between an image with and without an antagonistic patch provided by an embodiment of the present invention.

[0118] Figure 5 An optimized generated patch pattern and target stealth effect are provided by an embodiment of the present invention.

[0119] Figure 6 It is a schematic block diagram of an anti-patch generation device provided by an embodiment of the present invention.

[0120] Figure 7 It is a schematic block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0121] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0122] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts of the present invention.

[0123] If the technical solutions between the various embodiments of the present application can be combined with each other, it is based on the fact that ordinary technicians in the field can implement it.

[0124] It should be noted that the sequence numbers mentioned in this application do not necessarily mean that the steps must be strictly followed in the actual implementation process. The sequence numbers are used to distinguish each step for ease of explanation and to avoid confusion.

[0125] The accompanying drawings show schematic diagrams of layer structures according to embodiments of the present invention. These figures are not drawn to scale, and some details are magnified and some details may be omitted for the purpose of clarity. The shapes of various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are only exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may additionally design regions / layers with different shapes, sizes, and relative positions according to actual needs.

[0126] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0127] In the field of optical remote sensing, target detection technology based on DNNs has shown excellent performance. However, studies have found that DNNs are vulnerable to attacks by adversarial samples carefully designed by humans, resulting in detection errors, which hinders the deployment and application of intelligent detection algorithms. Research on adversarial texture generation technology can enable important targets to evade the detection of detectors on the one hand, and on the other hand, it can explore the loopholes of detectors, improve the robustness of detectors and the reliability of target detection results.

[0128] The adversarial attack method based on adversarial patches generates patches with specific textures and pastes them on the target to deceive the target detector, making it unable to accurately perceive the target. At present, adversarial patches are mainly obtained by attacking the target confidence loss or classification loss of the target detector through back-propagation iterative optimization. This method is limited to a specific detection network architecture and is not applicable to all detection networks. The loss function used to generate adversarial patches needs to be adjusted according to the detection network, which is relatively complicated.

[0129] Moreover, the adversarial patches optimized for the above-mentioned specific detection models have poor adversarial transferability and cannot attack other detection models.

[0130] In addition, the existing EOT enhancement algorithm only covers simple changes such as noise and lighting, and does not consider the impact of weather changes, motion blur, and patch direction changes on the adversarial effect from an aerial perspective. Therefore, in order to improve the effectiveness of adversarial patches in the physical world, it is necessary to consider more comprehensive external influencing factors.

[0131] In response to the above two problems, the present invention proposes a corresponding solution. In the design of the EOT algorithm, the changes of actual physical factors such as weather changes and motion blur are taken into account to construct a more robust adversarial patch. Secondly, in order to achieve a more general adversarial patch with stronger generalization performance, the detector output loss is combined with the target detection network output feature layer in the design of the attack objective function, thereby improving the generalization of the adversarial patch.

[0132] Based on the above inventive concept, the present invention provides a method and device for generating an adversarial patch.

[0133] In order to better understand the technical solution of the present invention, the terms that may be involved in the embodiments of the present invention are explained.

[0134] DNNS (Deep Neural Networks): Deep neural networks.

[0135] CNNS (Convolutional Neural Networks): Convolutional Neural Networks.

[0136] Patch: Adversarial patch.

[0137] Mask: Mask.

[0138] EOT (Expectation Of Transform): Expectation transform, references are as follows: Athalye A, Engstrom L, Ilyas A, et al. Synthesizing robust adversarial examples [C] / / International conference on machine learning. PMLR, 2018: 284-293.

[0139] YOLO (You Only Look Once): A real-time target detection algorithm, the references are as follows: Redmon, Joseph, et al. "You only look once: Unified, real-time object detection." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.

[0140] DOTA (Dataset of Object deTection in Aerial images): A large-scale dataset for object detection in aerial images. See the following references: J. Ding et al., "Object Detection in Aerial Images: A Large-Scale Benchmark and Challenges," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 44, no. 11, pp. 7778-7796, 1Nov. 2022, doi: 10.1109 / TPAMI.2021.3117983.

[0141] Albumentations: Albumentations is a Python library for image enhancement. The reference code and instructions are as follows:

[0142] https: / / github.com / albumentations-team / albumentations.

[0143] Backbone: Backbone network, a network used to extract features from input images.

[0144] Head: Detection head, used to predict the type and location of the target.

[0145] Neck: Located between Backbone and Head, it is a network layer used to perform multi-scale feature fusion on feature maps.

[0146] Backpropagation: A learning algorithm for multi-layer artificial neural networks that uses gradient descent to update weights to minimize a loss function.

[0147] An embodiment of the present invention provides a method for generating an adversarial patch, comprising:

[0148] Collect aerial images and annotate the targets to be attacked, train the target detection perception model, and generate adversarial patches;

[0149] Inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection respectively, and obtaining the adversarial patch image feature map and the non-patch image feature map respectively;

[0150] Calculating the feature maps outputted from the feature map of the adversarial patch image and the feature map of the non-patch image, and combining the output loss of the detection model to obtain a target loss function of the adversarial patch;

[0151] The gradient value is calculated according to the target loss function, and after back propagation, the pixel value of the adversarial patch is updated to complete the optimization of the adversarial patch.

[0152] The following is described by specific embodiments, see the attached Figure 1 shown.

[0153] S101: Collect aerial images and mark the targets to be attacked, train the target detection perception model, and generate adversarial patches;

[0154] Based on the aerial image as the input image, the size and shape of the initialization patch are set according to the size of the input image and the size and shape of the target, and the input image and the detection frame of the target are processed. The detection format of the target is not limited here, and the location and other information of the target to be attacked can be determined.

[0155] By setting the shape and size of the initial patch according to the target detection category and the scale relative to the aerial image, the gradient information of the adversarial patch can be retained so that the value of each pixel in the patch can be updated through gradient optimization.

[0156] The above information can be used to train the target detection perception model to generate adversarial patches. The adversarial patches are conventional adversarial patches and have not been optimized.

[0157] S102: inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, respectively, to obtain the adversarial patch image feature map and the non-patch image feature map;

[0158] Optionally, in order to improve the effect of the adversarial patch, EOT transformation and mapping operations may be performed before inputting the detection model for detection to improve the effect of the adversarial patch.

[0159] After obtaining the adversarial patch image and the image without the adversarial patch, they are respectively input into the detection model for detection to obtain the adversarial patch image feature map and the non-patch image feature map respectively.

[0160] The acquisition method can be a feature map extracted through the Backbone network and the Neck layer.

[0161] S103: Calculate the feature map outputted from the feature map of the adversarial patch image and the feature map of the non-patch image, and combine the output loss of the detection model to obtain the target loss function of the adversarial patch;

[0162] The two different feature maps of the output are calculated and processed, and the optimization loss of the adversarial patch can be calculated in combination with the loss output by the model Head.

[0163] Specifically, the feature maps of the model output image passing through the backbone and neck network (neck) and the detector loss can be calculated, and the target loss function of the adversarial attack can be obtained by combining the detector loss.

[0164] S104: Calculate the gradient value according to the target loss function, and after back propagation, update the pixel value of the adversarial patch to complete the optimization of the adversarial patch.

[0165] The gradient value is calculated from the loss, and the adversarial patch updates the pixel value after back propagation, thereby completing the optimization of the adversarial patch. After multiple rounds of iterative optimization, a patch with a robust adversarial effect for aerial images can be generated.

[0166] The technical solution of the embodiment of the present invention, after generating the initial adversarial patch, respectively inputs the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, respectively obtains the adversarial patch image feature map and the non-patch image feature map, then calculates the feature map output by the adversarial patch image feature map and the non-patch image feature map, and combines the output loss of the detection model to obtain the target loss function of the adversarial patch, which has a better target stealth effect. The technical solution of the embodiment of the present invention is the first adversarial texture generation method under the aerial perspective based on key feature area suppression, and can also be understood as a physical stealth attack method based on key feature area suppression, which not only considers the loss of the detection model output, but also considers the impact of the patch on the feature map, maximizes the difference between the patched and unpatched images in the detection model output tensor, can make the optimized generated patch have a more generalized attack effect, and at the same time enhances the black box migration performance of the patch, so that the patch still has a good adversarial effect on different detection models. The technical solution of the present invention is the first adversarial texture generation algorithm under aerial perspective based on suppression of key feature areas. In the prior art, the solution is obtained by attacking the target confidence loss or classification loss of the target detector and optimizing iteratively through back propagation. The method of the prior art is limited to a specific detection network architecture and is not applicable to all detection networks. The loss function for generating adversarial patches needs to be adjusted according to the detection network, which is relatively complicated. Therefore, the adversarial patch generation method of the prior art solution has the problem of poor transferability. The solution of the present invention combines the detector output loss with the target detection network output feature layer in the design of the attack target function, thereby improving the generalization of the adversarial patch. The feature map-based method can improve the generalization performance of the patch attack on the one hand, and can also be applied to a variety of detection models as a general method on the other hand, without the need to design the loss function according to the network structure. It is a more general adversarial patch with stronger generalization performance.

[0167] Optionally, as one embodiment, generating the adversarial patch specifically includes:

[0168] Marking the rotating frame of the target to be attacked according to the collected aerial image;

[0169] According to the detection category of the target to be attacked and the scale of the aerial image, the shape and size of the initial adversarial patch are set, and the gradient information of the initial adversarial patch is retained;

[0170] The image is read, the image data and the coordinates of the marked box of the target to be attacked are obtained, the marked box is processed, and the adversarial patch is generated.

[0171] Optionally, as one embodiment, retaining the gradient information of the initial adversarial patch specifically includes:

[0172] The value of the attribute required_grad of the initial adversarial patch is set to true, and the initial adversarial patch is passed to the optimizer object, so that the adversarial patch can update parameters according to the gradient value obtained by back propagation.

[0173] Optionally, as one embodiment, the processing of the annotation frame specifically includes:

[0174] The detection format of the target is YOLO format (x c ,y c , w, h, angle), where x c ,y c , w, h are used to determine the position of the target to be attacked, and angle determines the rotation direction of the target;

[0175] The detection frame information of the target to be attacked is normalized so that the value is within the range of [0, 1].

[0176] Optionally, as one embodiment, the reading the image specifically includes:

[0177] The read images have multiple batches, the batch size is B, and the image data dimension of each batch is (B×C×H×W);

[0178] Among them, H is the image height, W is the image width, and C is the number of image channels.

[0179] Optionally, as one embodiment, the normalizing the detection box information of the target to be attacked specifically includes:

[0180] The detection format of the target is YOLO format (x c ,y c , w, h, angle), use the following formulas 1, 2, 3, and 4 to normalize the target detection frame coordinates to obtain the normalized annotation frame information (x c ′,y c ′, w′, h′, angle);

[0181] Among them, formula 1 is as follows:

[0182]

[0183] Formula 2 is as follows:

[0184]

[0185] Formula 3 is as follows:

[0186]

[0187] Formula 4 is as follows:

[0188]

[0189] The following is an explanation through specific examples.

[0190] S1. Collect aerial images and annotate the target with a rotating box, and train the target detection perception model. Initialize the adversarial patch, set the shape and size of the initial patch according to the target detection category and the scale relative to the aerial image, and retain the gradient information of the adversarial patch so that the value of each pixel in the patch can be updated through gradient optimization.

[0191] Specifically, the specific plan can be as follows:

[0192] S11. Set the size and shape of the initialization patch according to the size of the input image and the size and shape of the target.

[0193] When initializing the adversarial patch, the shape and size of the initial patch can be set according to the corresponding target detection category and the scale relative to the aerial image, and the gradient information of the adversarial patch is retained so that the value of each pixel point of the patch can be gradient updated for iterative optimization.

[0194] The size of the input image is (H×W×C), where H is the image height, W is the image width, and C is the number of image channels. In RGB image format, C is 3. After normalization preprocessing, the image is converted into a tensor I of size (C×H×W). The size and shape of the initialization patch are set according to the size and shape of the target. Here, a square patch P is taken as an example, and its dimension is (C×A×A). The number of patch channels is consistent with the number of image channels, and A is the side length of the square patch.

[0195] S12. Gradient information should be retained during the patch training generation process, that is, the attribute required_grad = True is set, and the patch is passed to the optimizer object so that it can update the parameters according to the gradient value obtained by backpropagation to achieve iterative optimization of the patch.

[0196] S2. Read input data, obtain image data and the coordinates of the marked box of the attack target, pre-process the marked box, and obtain the width, height, center point coordinates and rotation angle information of the target box.

[0197] Specifically, images can be read in batches with a batch size of B, and the dimension of each batch of image data is (B×C×H×W). The coordinates of the annotation box of the target S to be attacked are obtained, and the annotation box is preprocessed to obtain the width, height, center point coordinates and rotation angle information of the target box, which are used for the subsequent EOT transformation of the adversarial patch and the operation of attaching the patch on the target to be attacked.

[0198] S21, process the input image and the target detection frame, the target detection format is YOLO format (x c ,y c , w, h, angle), where x c ,y c , w, h are used to determine the position of the target to be attacked. Different from the annotation method of the horizontal box, angle determines the rotation direction of the target.

[0199] Specifically, the read image and the detection frame of the target to be attacked are processed, and the target detection format is YOLO format (x c ,y c , w, h, angle), normalize the target detection frame coordinates to obtain the normalized annotation frame information (x c ′,y c ′, w′, h′, angle), as shown in formula (1) to formula (4), where the angle does not change in scale. In order to adapt to the situation where there are multiple attack targets in one image, the maximum number of attack targets for each input image is preset to n, which can be adjusted according to the density and number of attack targets in the data set. The dimension of the annotation box after preprocessing of each batch can be (B×n×5).

[0200]

[0201]

[0202]

[0203]

[0204] S22, normalize the detection box information of the target to be attacked, and take the value in the range of [0,1], while angle is independent of the image size and is not transformed. The processed detection box annotation information can be used for subsequent EOT transformation and mapping operations.

[0205] Optionally, as one embodiment, after generating the adversarial patch and before respectively inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, the method further includes:

[0206] Performing EOT transformation on the generated adversarial patch;

[0207] Performing an affine transformation on the adversarial patch;

[0208] The adversarial patch is placed at the target to be attacked in the original image size, and the patch is attached to the target to be attacked by replacing pixels.

[0209] Optionally, as one embodiment, performing EOT transformation on the generated adversarial patch specifically includes:

[0210] Performing median filtering preprocessing on the adversarial patch;

[0211] The number of patches after the preprocessing is expanded to a preset maximum number of attack targets;

[0212] Performing image enhancement transformation on the expanded adversarial patch;

[0213] The image enhancement transformation includes at least one of the spatial level transformations such as random addition of noise, contrast, brightness, motion blur, weather change pixel level transformation, random flipping, etc.

[0214] Optionally, as one embodiment, performing an affine transformation on the adversarial patch specifically includes:

[0215] Expanding the number of patches transformed by the EOT to a preset maximum number of attack targets;

[0216] According to the position of the target to be attacked in the image, the patch is scaled and rotated to the image attack target by using affine transformation to fit the target.

[0217] Optionally, as one embodiment, the image enhancement transformation specifically includes:

[0218] A transformation probability parameter P is provided for adjusting the probability of each of the image enhancement transformations;

[0219] The image enhancement transformation is performed using the following formula 5:

[0220] P′=EOT(P) (5)

[0221] Wherein, P′ is the transformed patch, and EOT() represents the EOT image enhancement processing performed on the adversarial patch.

[0222] Optionally, as one embodiment, the number of patches that undergo the image enhancement transformation is expanded to a preset maximum number of attack targets, specifically including:

[0223] Determining the number of attack targets for each image according to the labels of the targets to be attacked;

[0224] Create a Mask matrix tensor G′ with the same dimension as the adversarial patch tensor, where the Mask matrix tensor is used to identify the attack target, marking the position where the attack target exists as 1 and marking the other positions as 0;

[0225] The matrix tensor G′ and the adversarial patch P′ are padded to the same shape as the input image.

[0226] Optionally, as one embodiment, filling the matrix tensor G′ and the adversarial patch P′ into a shape having the same size as the input image specifically includes:

[0227] Output the matrix tensor G′, and paste the adversarial patch to the target to be attacked, wherein the positions of 0 in the matrix tensor adopt the pixel values ​​of the clean image, and the positions of non-0 adopt the pixel values ​​of the adversarial patch.

[0228] Optionally, as one embodiment, the affine transformation specifically includes:

[0229] The affine transformation process adopts Formula 6, as follows:

[0230]

[0231] Among them, x, y are the coordinates before affine transformation, x′, y′ are the coordinates after affine transformation, the first two columns are used to set the rotation angle θ and the scaling ratio scale to achieve rotation and scaling, and the third column is used to achieve image translation.

[0232] Optionally, as one embodiment, placing the adversarial patch at the target to be attacked at the original image size specifically includes:

[0233] According to the label information of the target to be attacked, resample the adversarial patch P′ to the target to be attacked;

[0234] Multiply the adversarial patch matrix tensor P′ by the matrix tensor G′ to obtain the output matrix P E ;

[0235] The output matrix P E The obtained adversarial patch is pasted to the position of the target to be attacked.

[0236] Optionally, as one embodiment, the output matrix P E , obtained using Formula 7, as follows:

[0237] P E=P′*G′ (7)

[0238] Among them, the output matrix P E , the pixel value at the patch of the target to be attacked is not 0, and the other pixel values ​​are 0.

[0239] Optionally, as one embodiment, the output matrix P E The obtained adversarial patch is pasted to the position of the target to be attacked, specifically including:

[0240] The output matrix P E The positions of the tensor that are 0 use the pixel values ​​of the clean image, and the positions that are not 0 use the output matrix P E Generate the adversarial patch according to the pixel value at the corresponding index;

[0241] Paste the countermeasure patch to the position of the target to be attacked;

[0242] Among them, the image tensor I of the adversarial patch p , the dimension is the same as the dimension of the image data in each batch.

[0243] The above embodiment is continued to be described as an example.

[0244] S3, the generated adversarial patch is subjected to EOT transformation, and noise, contrast, brightness, motion blur, weather changes and other pixel-level changes as well as flipping and other spatial-level transformations are randomly added to the original patch, such as Figure 2 As shown in the figure, a more robust adversarial patch is constructed to simulate the impact of changing factors in the real physical world. After affine transformation, the patch is placed at the target of the original image size, and the patch can be placed at the attack target by replacing pixels.

[0245] More specifically, as follows:

[0246] S31, performing EOT transformation on the patch, first performing median filtering preprocessing on the patch to improve the noise resistance of the patch.

[0247] S32, perform image enhancement transformation on the preprocessed patch to simulate the conditions that may exist in the physical world, including common random noise, random brightness contrast, and motion blur, weather changes, random flipping, etc. that may exist in aerial images. The specific method can use the third-party tool Albumentations library to achieve the enhancement transformation of the patch image. The specific steps are as follows:

[0248] First, the required image transformation operation is defined, and the transformation probability of each image enhancement can be adjusted by the transformation probability parameter p.

[0249] Random noise, random brightness contrast, and motion blur correspond to the GaussNoise(·), RandomBrightnessContrast(·), and MotionBlur(·) functions respectively. The weather transformation functions include random fog RandomFog(·), random rain RandomRain(·), random snowflakes RandomSnow(·), and random sun flare effect RandomSunFlare(.). The above pixel-level transformations simulate the influencing factors that may exist in the physical world.

[0250] In addition to the above, the Flip(·) function can also be used to randomly flip the patch, including horizontal, vertical, and horizontal and vertical flips, to improve the robustness of the patch in terms of direction, so that the patch can be placed on the target in any direction.

[0251] EOT(.) represents the EOT image enhancement operation performed on the patch, and the patch processed by the EOT algorithm is P′.

[0252] P′=EOT(P) (5)

[0253] S33, expanding the number of patches after image enhancement to the preset maximum number of attack targets. The number of attack targets for each image can be determined according to the target labels of the image to be attacked, and a Mask matrix tensor with the same dimension as the patch tensor is created to identify the attack targets, and the positions where the attack targets exist are set to 1, and the remaining positions are set to 0.

[0254] More specifically, it can be as follows:

[0255] The P' tensor is expanded to a tensor P' with a preset maximum number of attack targets and a dimension of (B×n×C×A×A). The number of attack targets for each image can be determined based on the target labels of the image to be attacked, and a matrix tensor G is created with the same dimension as P'. The positions where the attack targets exist are set to 1 (determined by the subscript n), and the remaining positions are set to 0, which is used as the mask tensor G' of the patch. Finally, the tensors G' and P' are filled to the same shape as the input image, with a filling value of 0 and a dimension of (B×n×C×H×W).

[0256] S34, determine the position of the attack target in the image according to the target label, and use affine transformation to scale and rotate the patch to the image attack target to fit the target. Finally, multiply the patch tensor with the Mask matrix tensor that identifies the attack target, and the output tensor is 0 except for the pixel value at the patch target position. Use the output tensor to paste the patch to the target, and use the pixel value of the clean image for the position with 0 in the output matrix, and use the output matrix value, that is, the pixel value of the adversarial patch, for the position with non-0, thereby realizing the operation of pasting the patch at the target to be attacked.

[0257] Specifically, the position of the attack target in the image is determined according to the target label, and the patch is scaled and rotated to the image attack target using affine transformation to fit the target. The affine transformation process can be expressed as formula (6).

[0258]

[0259] Among them, x, y are the coordinates before affine transformation, x′, y′ are the coordinates after affine transformation. The first two columns can set the rotation angle θ and the scaling ratio scale to achieve the effect of rotation and scaling, and the third column realizes the translation of the image. According to the annotation information of the target to be attacked, the patch can be resampled to the target to be attacked.

[0260] Finally, the patch matrix tensor P′ is multiplied with the mask tensor G′, as shown in formula (7), and the output matrix P E Except for the pixel value where the patch of the target to be attacked is placed, the rest are all 0.

[0261] P E =P′*G′ (7)

[0262] Using the output matrix P E The patch is applied to the target. The positions with zero in the output tensor use the pixel values ​​of the clean image, and the positions with non-zero values ​​use the pixel values ​​of P E The pixel value at the corresponding index, such as Figure 3 shown.

[0263] The patched image tensor is I p , the dimension is the same as I, that is, the dimension of each batch of image data is (B×C×H×W).

[0264] The technical solution of the embodiment of the present invention proposes an EOT algorithm for aerial images. According to the characteristics of aerial images, factors affecting the patch adversarial effect, such as changes in lighting conditions, motion blur, and weather changes, are considered. At the same time, random flipping is added in the process of generating patches, which reduces the sensitivity of patches to the posting direction. The EOT algorithm effectively enhances the applicability of patches in different scenarios. Compared with the EOT enhancement algorithm in the prior art, which only covers simple changes such as noise and lighting, and does not consider the impact of weather changes, motion blur, and patch direction changes on the adversarial effect under the aerial perspective, a new solution is provided. The technical solution of the present invention transforms the adversarial patch during training in the digital world, adds noise, weather changes, shape changes, and other operations to simulate the possible situations in the physical world, so that the adversarial patch has better generalization performance. Therefore, the embodiment of the present invention improves the effectiveness of the adversarial patch in the physical world, considers more comprehensive external influencing factors, and has a better adversarial effect. Moreover, the technical solution of the embodiment of the present invention, based on the suppression of key feature areas, sets 0 for images that do not belong to the key area. Therefore, in the calculation process, it can effectively save computing resources, and the transformation is performed on the key area, and the effect is good.

[0265] Optionally, as one embodiment, before inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, the method further includes:

[0266] According to the labeling information of the target to be attacked, the image with the adversarial patch and the image without the adversarial patch are processed separately to generate a Mask tensor that only displays the target to be attacked.

[0267] Optionally, as one embodiment, the step of inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection to obtain the adversarial patch image feature map and the non-patch image feature map, respectively, specifically includes:

[0268] The image with the adversarial patch and the image without the adversarial patch are respectively input into the target detection model for detection, and the feature maps passing through the backbone network and the neck network are respectively obtained, and the feature map of the adversarial patch image and the feature map of the non-patch image are extracted.

[0269] Optionally, as one embodiment, the processing the image with the adversarial patch and the image without the adversarial patch separately includes:

[0270] Obtaining position information of the target detection frame according to the position of the target in the original image;

[0271] Initialize the Mask tensor T and set all to 0. According to the position of the target in the target detection frame in the image, fill the pixels at the position of the target with 1 to obtain a binary Mask tensor T that only displays the target to be attacked. ′ ;

[0272] The output tensor I of the image of the adversarial patch p , and the tensor T that only displays the attack targets ′ Multiplying, so that the pixel values ​​of the image other than the target to be attacked are all set to 0, only the pixels at the target are displayed, and the target to be attacked has a patch;

[0273] The non-patch clean image tensor I is compared with the tensor T that only shows the attack target ′ Multiplying them makes the pixel values ​​of the image other than the attack target all be set to 0, only the pixels at the attack target are displayed, and the attack target does not have an adversarial patch.

[0274] Optionally, as one embodiment, the multiplication of the non-patch clean image tensor I and the tensor T′ showing only the attack target specifically includes:

[0275] Formula 8 is used to multiply the non-patch clean image tensor I by the tensor T′ showing only the attack target. The formula 8 is as follows:

[0276] I′=I*T′ (8).

[0277] Optionally, as one embodiment, the output tensor I of the image of the adversarial patch is p , multiplied by the tensor T′ that only displays the attack target, specifically including:

[0278] Formula 9 is used to multiply the non-patch clean image tensor I by the tensor T′ showing only the attack target. The formula 9 is as follows:

[0279] I p ′=I p *T′ (9).

[0280] Optionally, as one embodiment, calculating the feature map outputted from the adversarial patch image feature map and the non-patch image feature map, and combining the output loss of the detection model to obtain the target loss function of the adversarial patch specifically includes:

[0281] The feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network p, subtract according to the corresponding layer, and map the output value to the interval [0, 1], add the classification loss or target loss in the output loss of the detection model, negate it and add 1, as the target loss function of the adversarial patch.

[0282] Optionally, as one embodiment, the feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network p , subtract according to the corresponding layer, including:

[0283] Formula 10 is used to convert the feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the neck network with the adversarial patch image p , subtract according to the corresponding layer, the formula 10 is as follows:

[0284] R(i)=F(i)-F p (i), i = 1, 2, ... L (10)

[0285] Among them, i represents the feature map of the i-th layer, and the number of feature maps is L.

[0286] Optionally, as one embodiment, the method for obtaining the loss function of the i-th layer feature map includes:

[0287] Formula 11 is used to calculate the loss function of the feature map of the i-th layer, as follows:

[0288]

[0289] Among them, L feature (i) represents the feature map loss of the i-th layer, Abs(·) represents the absolute value function, and sum(·) represents the sum function. sum(R(i)≠0) represents the sum of the number of non-zero elements in R(i).

[0290] Optionally, as one embodiment, mapping the output value to the interval [0, 1] specifically includes:

[0291] The loss function L of each layer feature map will be calculated feature (i) Sum and use the sigmoid function to map it to the interval [0, 1] to obtain the attack loss L attack , as shown in Formula 12:

[0292]

[0293] Among them, the calculation process of the sigmoid() function is shown in Formula 13:

[0294]

[0295] Optionally, as one embodiment, mapping the output value to the interval [0, 1], adding the classification loss or target confidence loss in the output loss of the detection model, negating it and adding 1, as the target loss function of the adversarial patch, specifically includes:

[0296] The objective loss function L of the adversarial patch adv Yes, it can be determined by formula 14:

[0297] L adv =1-aL attack +β*L cls / object (14)

[0298] Where α and β are adjustment coefficients, so that the value of the target loss function of the adversarial patch is in a reasonable range, L attack To map the output value to the [0, 1] interval to obtain the attack loss, L cls represents the classification loss of the detection model, L object Represents the target confidence loss.

[0299] The above embodiment is continued to be described as an example.

[0300] S4. Create a Mask tensor that only displays the target according to the annotation information of the target to be attacked, and process the input image data so that the values ​​of the remaining pixel positions of the input image except the target are all 0. The image with the adversarial patch and the clean image without the adversarial patch are input into the detection model for detection. The model output image passes through the feature map of Backbone and Neck, and the feature maps of the two outputs are calculated and combined with the loss of the model output as the target loss function of the adversarial attack.

[0301] Specifically, the image tensor data I and I are tagged according to the label information of the target to be attacked. p Processing is performed so that the values ​​of all pixel positions except the attack target are 0. The image with the adversarial patch and the clean image without the adversarial patch are input into the detection model for detection. The model output image passes through the feature map of the Backbone and neck network and the detector loss, and the feature map output by the two is calculated, and the target loss function of the adversarial attack is obtained by combining the detector loss.

[0302] Further, detailed specific steps can be as follows:

[0303] S41. The target position can be found in the original image according to the target detection frame, and the target detection frame format is converted into DOTA format, that is, the positions of the four vertices of the detection frame (x0, y0, x1, y1, x2, y2, x3, y4). The Mask of the input image size is initialized and all are set to 0. Then, according to the detection frame information, the pixels at the target position to be attacked are filled with 1. From then on, the Mask that only displays the target and sets all other pixels to 0 is completed.

[0304] The angle calculation adopts the le90 mode. Initialize the Mask tensor T with dimensions (H, W, C) and set all to 0. Fill the position of the target in the image with 1 according to the target detection frame, and thus complete the binary Mask tensor T′ that only displays the target to be attacked.

[0305] S42, multiply the patched output tensor with the Mask tensor that only displays the attack target, and this step sets all pixel values ​​outside the target to 0, and only displays the pixels at the target, and the target is patched. Similarly, the clean image without the patch is multiplied with the Mask tensor that only displays the attack target, and all pixel values ​​outside the target are set to 0, and only the pixels at the target are displayed, and the target is not patched.

[0306] The patched output tensor I p Multiply it with the Mask tensor T′ that only displays the attack target. This step sets all pixel values ​​outside the target to 0, only displays the pixels at the target, and the target is patched. Similarly, multiply the clean image I without the patch by the Mask tensor T′ that only displays the attack target, so that all pixel values ​​outside the target are set to 0, and only displays the pixels at the target, and the target is not patched. The process is shown in formulas (8) and (9):

[0307] I′=I*T′ (8)

[0308] I p ′=I p *T′ (9)

[0309] S43. The patched and unpatched images are respectively sent to the target detection model, and the feature maps extracted by the Backbone network and the Neck layer are output. The two different feature maps are calculated and processed, and the optimization loss of the adversarial patch is calculated by combining the loss output by the model Head.

[0310] The patched image I p ′ and the image I′ without patch are input into the detection model respectively, and the feature map extracted by the Backbone network and the Neck layer is output.

[0311] The two different feature maps output are calculated and processed and combined with the detection model Head detection head output loss to obtain the objective function of adversarial patch generation.

[0312] Furthermore, the specific steps can be as follows:

[0313] S421, subtract the feature maps output by two different images according to the corresponding layers, calculate the average value of the tensor value after subtraction that is not 0, use the sigmoid function to map the output value to the interval [0, 1], add the classification loss or target loss output by the model on this basis, take the inverse and add 1 as the final adversarial patch loss function. Multiply the adjustment coefficient at the two losses to make the loss decline trend more obvious.

[0314] The following is a detailed description. The feature map F without patch image output and the feature map F with patch image output p , subtract according to the corresponding layer, as shown in formula (10), use the sigmoid function to map the output value to the interval [0, 1], and add the classification loss or target loss in the detection model output loss, negate it and add 1 as the final adversarial loss.

[0315] R(i)=F(i)-F p (i), i = 1, 2, ... L (10)

[0316] Among them, i represents the feature map of the i-th layer, and the number of feature maps is L.

[0317] Calculate the loss function of each layer of feature map as shown in formula (11):

[0318]

[0319] Among them, L feature (i) represents the feature map loss of the i-th layer, Abs(·) represents the absolute value function, and sum(·) represents the sum function. sum(R(i)≠0) represents the sum of the number of elements in R(i) that are not 0. feature (i) Sum and map it to the [0, 1] interval using the sigmoid function, as shown in formula (12):

[0320]

[0321] The calculation process of the sigmoid(·) function is shown in formula (13):

[0322]

[0323] The final adversarial loss L adv It can be obtained from formula (14):

[0324] L adv =1-aL attack +β*L cls / object (14)

[0325] Among them, α and β are adjustment coefficients, which are used to ensure that the adversarial loss is in a reasonable range, and the downward trend of the loss can be clearly observed with the increase of the number of iterations.

[0326] S5. The gradient value is calculated from the loss, and the adversarial patch updates the pixel value after back propagation, thereby completing the optimization of the adversarial patch. After multiple rounds of iterative optimization, a patch with a robust adversarial effect for aerial images can be generated.

[0327] The steps of calculating the gradient value of the loss and updating the pixel value of the adversarial patch after back propagation are consistent with the steps of the solution in the prior art and will not be described in detail here. Those skilled in the art can optimize the adversarial patch according to the above steps.

[0328] The technical solution of the present invention is an adversarial texture generation algorithm under the aerial perspective based on the suppression of key feature areas. It not only considers the loss of the detection model output, but also considers the influence of the patch placement on the feature map, and maximizes the difference in the output tensor of the patched and unpatched images in the Neck layer of the detection model, so that the optimized generated patch has a more generalized attack effect, and at the same time strengthens the black box migration performance of the patch, so that the patch still has a good adversarial effect on different detection models. The technical solution of the present invention selects the output feature map of the neck layer instead of the output of the head layer to design the loss function, which can realize the attack of shallower features, thereby improving the generalization performance of the adversarial patch. The target detection adversarial attack method provided in the embodiment of the present invention is mainly to solve the white box attack of known model parameters and architecture, but the method is also applicable to the attack of the alternative model under the black box condition, and then migrated to the target model. The target detector used in the present invention is a two-stage detection algorithm, but it is also applicable to single-stage and multi-stage detection algorithms. The present invention is mainly aimed at the challenges under the attack of the physical world, but it is also applicable to the attack of the digital world image.

[0329] The embodiment of the present invention further provides a device 600 for generating a countermeasure patch, such as Figure 6 As shown, including:

[0330] A generation module 601 is used to collect aerial images and mark the targets to be attacked, train the target detection perception model, and generate adversarial patches;

[0331] The optimization module 602 is used to input the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, respectively, to obtain the adversarial patch image feature map and the non-patch image feature map; it is also used to calculate the feature maps output by the adversarial patch image feature map and the non-patch image feature map, and combine the output loss of the detection model to obtain the target loss function of the adversarial patch; it is also used to calculate the gradient value according to the target loss function, and after back propagation, update the pixel value of the adversarial patch to complete the optimization of the adversarial patch.

[0332] The embodiment of the present invention further provides an electronic device 700, such as Figure 7 As shown, it includes a memory 701, a processor 702, and a computer program stored in the memory 701 and executable on the processor. When the processor 702 executes the program, the steps of the method described in any one of the above embodiments are implemented.

[0333] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in any one of the above embodiments are implemented.

[0334] Obviously, the described embodiments are only some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0335] It should be understood that the above specific embodiments of the present invention are only used to illustrate or explain the principles of the present invention, and do not constitute a limitation of the present invention. Therefore, any modifications, equivalent substitutions, improvements, etc. made without departing from the spirit and scope of the present invention should be included in the protection scope of the present invention. In addition, the appended claims of the present invention are intended to cover all changes and modifications that fall within the scope and boundaries of the appended claims, or the equivalent forms of such scope and boundaries.

Claims

1. A method for generating adversarial patches, It is characterized in that include: Collect aerial images and annotate the targets to be attacked, train the target detection perception model, and generate adversarial patches; Inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection respectively, and obtaining the adversarial patch image feature map and the non-patch image feature map respectively; Calculating the feature maps outputted from the feature map of the adversarial patch image and the feature map of the non-patch image, and combining the output loss of the detection model to obtain a target loss function of the adversarial patch; The gradient value is calculated according to the target loss function, and after back propagation, the pixel value of the adversarial patch is updated to complete the optimization of the adversarial patch.

2. The method according to claim 1, It is characterized in that The generating of the adversarial patch specifically includes: Marking the rotating frame of the target to be attacked according to the collected aerial image; According to the detection category of the target to be attacked and the scale of the aerial image, the shape and size of the initial adversarial patch are set, and the gradient information of the initial adversarial patch is retained; The image is read, the image data and the coordinates of the marked box of the target to be attacked are obtained, the marked box is processed, and the adversarial patch is generated.

3. The method according to claim 2, It is characterized in that The retaining the gradient information of the initial adversarial patch specifically includes: The value of the attribute required_grad of the initial adversarial patch is set to true, and the initial adversarial patch is passed to the optimizer object, so that the adversarial patch can update parameters according to the gradient value obtained by back propagation.

4. The method according to claim 1, It is characterized in that The processing of the annotation frame specifically includes: The detection format of the target is YOLO format (x c ,y c ,w,h,angle), where x c ,y c ,w,h is used to determine the position of the target to be attacked, and angle determines the rotation direction of the target; The detection frame information of the target to be attacked is normalized so that the value is within the range of [0, 1].

5. The method according to claim 1, It is characterized in that The reading of the image specifically includes: The read images have multiple batches, the batch size is B, and the image data dimension of each batch is (B×C×H×W); Among them, H is the image height, W is the image width, and C is the number of image channels.

6. The method according to claim 4, It is characterized in that The normalizing the detection frame information of the target to be attacked specifically includes: The detection format of the target is YOLO format (x c ,y c ,w,h,angle), use the following formulas 1, 2, 3, and 4 to normalize the target detection frame coordinates to obtain the normalized annotation frame information (x c ′,y c ′,w′,h′,angle); Among them, formula 1 is as follows: Formula 2 is as follows: Formula 3 is as follows: Formula 4 is as follows:

7. The method according to claim 1, It is characterized in that After generating the adversarial patch, and before respectively inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, the method further includes: Performing EOT transformation on the generated adversarial patch; Performing an affine transformation on the adversarial patch; The adversarial patch is placed at the target to be attacked in the original image size, and the patch is attached to the target to be attacked by replacing pixels.

8. The method according to claim 7, It is characterized in that The step of performing EOT transformation on the generated adversarial patch specifically includes: Performing median filtering preprocessing on the adversarial patch; The number of patches after the preprocessing is expanded to a preset maximum number of attack targets; Performing image enhancement transformation on the expanded adversarial patch; The image enhancement transformation includes at least one of the spatial level transformations such as random addition of noise, contrast, brightness, motion blur, weather change pixel level transformation, random flipping, etc.

9. The method according to claim 7, It is characterized in that The performing an affine transformation on the adversarial patch specifically includes: Expanding the number of patches transformed by the EOT to a preset maximum number of attack targets; According to the position of the target to be attacked in the image, the patch is scaled and rotated to the image attack target by using affine transformation to fit the target.

10. The method according to claim 8, It is characterized in that The image enhancement transformation specifically includes: A transformation probability parameter P is provided for adjusting the probability of each of the image enhancement transformations; The image enhancement transformation is performed using the following formula 5: P′=EOT(P) (5) Wherein, P′ is the transformed patch, and EOT() represents the EOT image enhancement processing performed on the adversarial patch.

11. The method according to claim 9, It is characterized in that The step of expanding the number of patches that have undergone the image enhancement transformation to a preset maximum number of attack targets specifically includes: Determining the number of attack targets for each image according to the labels of the targets to be attacked; Create a Mask matrix tensor G′ with the same dimension as the adversarial patch tensor, where the Mask matrix tensor is used to identify the attack target, marking the position where the attack target exists as 1 and marking the other positions as 0; The matrix tensor G′ and the adversarial patch P′ are padded to the same shape as the input image.

12. The method according to claim 11, It is characterized in that Filling the matrix tensor G′ and the adversarial patch P′ into a shape having the same size as the input image specifically includes: Output the matrix tensor G′, and paste the adversarial patch to the target to be attacked, wherein the positions of 0 in the matrix tensor adopt the pixel values ​​of the clean image, and the positions of non-0 adopt the pixel values ​​of the adversarial patch.

13. The method according to claim 7, It is characterized in that The affine transformation specifically includes: The affine transformation process adopts Formula 6, as follows: Among them, x, y are the coordinates before affine transformation, x′, y′ are the coordinates after affine transformation, the first two columns are used to set the rotation angle θ and the scaling ratio scale to achieve rotation and scaling, and the third column is used to achieve image translation.

14. The method according to claim 12, It is characterized in that Placing the adversarial patch at the target to be attacked at the original image size specifically includes: According to the label information of the target to be attacked, resample the adversarial patch P′ to the target to be attacked; Multiply the adversarial patch matrix tensor P′ by the matrix tensor G′ to obtain the output matrix P E ; The output matrix P E The obtained adversarial patch is pasted to the position of the target to be attacked.

15. The method according to claim 14, It is characterized in that The output matrix P E , obtained using Formula 7, as follows: P E =P′*G′ (7) Among them, the output matrix P E , the pixel value at the patch of the target to be attacked is not 0, and the other pixel values ​​are 0.

16. The method according to claim 14, It is characterized in that The output matrix P E The obtained adversarial patch is pasted to the position of the target to be attacked, specifically including: The output matrix P E The positions of the tensor that are 0 use the pixel values ​​of the clean image, and the positions that are not 0 use the output matrix P E Generate the adversarial patch according to the pixel value at the corresponding index; Paste the countermeasure patch to the position of the target to be attacked; Among them, the image tensor I of the adversarial patch p , the dimension is the same as the dimension of the image data in each batch.

17. The method according to claim 1, It is characterized in that Before inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, the method further includes: According to the labeling information of the target to be attacked, the image with the adversarial patch and the image without the adversarial patch are processed separately to generate a Mask tensor that only displays the target to be attacked.

18. The method according to claim 1, It is characterized in that The step of inputting the image with the adversarial patch and the image without the adversarial patch into the detection model for detection respectively, and obtaining the adversarial patch image feature map and the non-patch image feature map respectively, specifically includes: The image with the adversarial patch and the image without the adversarial patch are respectively input into the target detection model for detection, and the feature maps passing through the backbone network and the neck network are respectively obtained, and the feature map of the adversarial anti-patch image and the feature map of the non-patch image are extracted.

19. The method according to claim 17, It is characterized in that The processing of the image with the adversarial patch and the image without the adversarial patch respectively specifically includes: Obtaining position information of the target detection frame according to the position of the target in the original image; Initialize the Mask tensor T and set all of them to 0, fill the pixels at the position of the target in the target detection frame with 1 according to the position of the target in the image, and obtain a binary Mask tensor T′ that only displays the target to be attacked; The output tensor I of the image of the adversarial patch p , multiplied by the tensor T′ that only displays the attack target, so that the pixel values ​​of the image other than the target to be attacked are all set to 0, only the pixels at the target are displayed, and the target to be attacked has a patch; The non-patch clean image tensor I is multiplied by the tensor T′ that only displays the attack target, so that the pixel values ​​of the image other than the attack target are all set to 0, and only the pixels at the attack target are displayed, and the attack target does not have an adversarial patch.

20. The method according to claim 19, It is characterized in that The multiplication of the non-patch clean image tensor I and the tensor T′ showing only the attack target specifically includes: Formula 8 is used to multiply the non-patch clean image tensor I by the tensor T′ showing only the attack target. The formula 8 is as follows: I′=I*T′ (8).

21. The method according to claim 19, It is characterized in that The output tensor I of the image of the adversarial patch p , multiplied by the tensor T′ that only displays the attack target, specifically including: Formula 9 is used to multiply the non-patch clean image tensor I by the tensor T′ showing only the attack target. The formula 9 is as follows: I p ′=I p *T′ (9)。 22. The method according to claim 1, It is characterized in that The calculating the feature map outputted from the adversarial patch image feature map and the non-patch image feature map, and combining the output loss of the detection model to obtain the target loss function of the adversarial patch, specifically includes: The feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network p , subtract according to the corresponding layer, and map the output value to the [0,1] interval, add the classification loss or target confidence loss in the output loss of the detection model, negate it and add 1 as the target loss function of the adversarial patch.

23. The method according to claim 21, It is characterized in that The feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network p , subtract according to the corresponding layer, including: Formula 10 is used to convert the feature map F obtained by passing the non-patch image through the neck network and the feature map F obtained by passing the adversarial patch image through the neck network. p , subtract according to the corresponding layer, the formula 10 is as follows: R(i)=F(i)-F p (i),i=1,2,…L (10) Among them, i represents the feature map of the i-th layer, and the number of feature maps is L.

24. The method according to claim 23, It is characterized in that The method for obtaining the loss function of the i-th layer feature map includes: Formula 11 is used to calculate the loss function of the feature map of the i-th layer, as follows: Among them, L feature (i) represents the feature map loss of the i-th layer, Abs(·) represents the absolute value function, and sum(·) represents the sum function. sum(R(i)≠0) represents the sum of the number of non-zero elements in R(i).

25. The method according to claim 22, It is characterized in that Mapping the output value to the interval [0,1] specifically includes: The loss function L of each layer feature map will be calculated feature (i) Sum and use the sigmoid function to map it to the [0,1] interval to obtain the attack loss L attack , as shown in Formula 12: The calculation process of the sigmoid() function is shown in Formula 13:

26. The method according to claim 22, It is characterized in that The output value is mapped to the interval [0, 1], the classification loss or target confidence loss in the output loss of the detection model is added, the inverse is added to 1, and the target loss function of the adversarial patch is specifically as follows: The objective loss function L of the adversarial patch adv , determined using Formula 14: L adv 1-aL attack +β*L cls / object (14) Where α and β are adjustment coefficients used to make the value of the target loss function of the adversarial patch within a reasonable range, L attack Represents the attack loss obtained by mapping the output value to the interval [0,1], L cls represents the classification loss of the detection model, L object Represents the target confidence loss.

27. A device for generating an adversarial patch, It is characterized in that include: The generation module is used to collect aerial images and annotate the targets to be attacked, train the target detection perception model, and generate adversarial patches; The optimization module is used to input the image with the adversarial patch and the image without the adversarial patch into the detection model for detection, respectively, to obtain the adversarial patch image feature map and the non-patch image feature map; it is also used to calculate the feature maps output by the adversarial patch image feature map and the non-patch image feature map, and combine the output loss of the detection model to obtain the target loss function of the adversarial patch; it is also used to calculate the gradient value according to the target loss function, update the pixel value of the adversarial patch after back propagation, and complete the optimization of the adversarial patch.

28. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the steps of the method according to any one of claims 1 to 26 are implemented.

29. A computer-readable storage medium having a computer program stored thereon, Features: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 26 are implemented.

Citation Information

Cited By

  • Adversarial patch generation method and device for monocular depth estimation method

    CN119417875A

  • High-quality binary stripe generation method based on 2 +1 phase shift algorithm

    CN119741428A