A method for generating adversarial samples

Through the greedy local search method, slight perturbation of key pixel points and their neighbors in the image is solved, and the error classification problem of deep neural networks in the face of black box model is achieved, and the universality and efficiency of adversarial sample generation is achieved. Suitable for a variety of target recognition networks.

CN114419358BActive Publication Date: 2024-11-01NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111214760.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-19
Publication Date
2024-11-01
Estimated Expiration
2041-10-19

AI Technical Summary

Technical Problem

Deep neural networks are prone to misclassification when facing adversarial interference, and the prior art is difficult to effectively deal with adversarial attacks in black box models, especially weak opponents who do not understand network architecture, parameters or training data.

Method used

The greedy local search method is used to construct adversarial samples to achieve error classification of images by slight perturbing the key pixel points and their neighbors in the image. The specific steps include standardizing the image, randomly selecting pixel points for perturbation, calculating the prediction probability of the new image, and selecting the most influential point for further perturbation until the attack is successful.

Benefits of technology

It realizes universality and high availability of counterattack attacks, is suitable for multiple target recognition networks, can quickly lead to image target recognition failure, reduce the number of rounds to find key pixel points, and select key points through model feedback for perturbation analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114419358B_ABST
    Figure CN114419358B_ABST
Patent Text Reader

Abstract

A method for generating adversarial samples, based on perturbing the adjacent areas of key pixels and greedy local search technology, generates adversarial samples that misclassify the target image according to the relevant pixels extracted from the image and perturbing the pixels in the adjacent positions. The present invention extracts key pixels from the image, perturbs its neighborhood, and constructs tiny perturbations through the greedy local search method, thereby achieving image misclassification. The simplicity and effectiveness of this method can be used as a touchstone for designing robust networks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of pattern recognition, and in particular relates to a method for generating adversarial samples. Background Art

[0002] Deep neural networks are powerful and popular learning models that achieve state-of-the-art pattern recognition performance in many computer vision, speech, and language processing tasks. However, these networks are also susceptible to carefully crafted adversarial perturbations that lead to misclassification of inputs. Adversarial examples are attempts by an adversary to subvert the expected system behavior, leading to undesirable outcomes and potentially posing security risks when these systems are deployed in the real world.

[0003] There are two main directions of research on adversarial attacks based on different assumptions about the adversarial knowledge of the target network. In the first direction, the adversary is assumed to have detailed knowledge of the network architecture and parameters resulting from training (or access to labeled training sets). The adversary uses this information to construct a perturbation to a given image, the most effective methods being gradient-based. In the second direction, the adversary restricts its knowledge of the network to being able to observe the network's output only on certain probing inputs. This black-box model is a more realistic and applicable threat model, but it is also more challenging because it considers weak adversaries who have no knowledge of the network architecture, parameters, or training data. Summary of the invention

[0004] The technical problem to be solved by the present invention is to overcome the shortcomings of the prior art and provide an adversarial sample generation method, which extracts key pixel points in an image, perturbs its neighborhood, and constructs tiny perturbations through a greedy local search method, thereby achieving image misclassification.

[0005] The present invention provides a method for generating adversarial samples, comprising the following steps:

[0006] Step S1: Input image I and standardize the image. The standardized image has the same size as the original image. All coordinates of the standardized image are within the range [LB, UB]. LB and UB are two constants, and LB < 0, UB > 0. Use T∈R l×w×h represents the space of all valid images that satisfy the above properties; for each I∈Τ, all coordinates in the image satisfy (b,x,y)∈[l]×[w]×[h],I(b,x,y)∈[LB,UB];

[0007] Step S2, the classification label is C(I)∈{1,...,C}, p and r are perturbation coefficients, the side length of the image neighborhood search radius is 2d, the maximum number of iterations is R, and the number of pixels selected in each iteration is t;

[0008] Step S3: Randomly select 10% of the pixels and initialize the set (P x ,P y ), (P x ,P y ) i is a set of pixel positions; the first round (P x ,P y )0 is randomly generated; in each subsequent round, it is formed based on a set of pixel positions that were disturbed in the previous round; let (P x ,P y ) i-1 represents the middle pixel position of the disturbed area in round i-1, then

[0009] Step S4, traverse (P x ,P y ) pixels, perturb PRER(I,p,x,y) to obtain a new image set;

[0010] The perturbation method is PETR(I,p,x,y)=p×sign(I(*,x,y)), where sign is the sign function, defined as

[0011] Step S5: Calculate the probability score (I) of each image in the new image set predicting the original classification label; select t pixels with the largest probability to obtain a new pixel set (P x ,P y ); traverse(P x ,P y ), for (x,y)∈(P x ,P y ) neighborhood, perform perturbation RangeAdv(r,b,x,y), and update the original image I; the range perturbation method is

[0012] Step S6: If If the attack is successful, the attack ends; otherwise, the attack model is defined as NN, and the classification result of NN is: NN(I)=(o1,...,o c ), where o i is the probability of the image being identified as the i-th label; π(NN(I p ), k) are the topk labels of the classification of the model NN for the image I;

[0013] Step S7, traverse (P x ,P y ), with each pixel as the center, draw a square with a side length of 2d, and all points within the square are included (Px ,P y ), go to step S4.

[0014] As a further technical solution of the present invention, from (P x ,P y ) set, randomly select up to 128 points, traverse each point, perturb each point and generate a new image to obtain a new image set; calculate each image in the new image set to obtain the probability value of being classified as the original label.

[0015] Furthermore, after data normalization, all coordinates are between [-0.5, 0.5].

[0016] The advantages of the present invention are:

[0017] 1. Versatility of adversarial attacks.

[0018] 2. Applicable to a variety of target recognition networks, that is, there is no need to consider the network architecture.

[0019] 3. It has high availability and can cause image target recognition failure by adding tiny disturbances.

[0020] 4. Reduce the number of rounds of searching for key pixels. By adding disturbances to key pixels and their neighborhoods, image classification errors can be quickly corrected.

[0021] 5. Select the disturbed points based on the feedback information of the model, and then select the points around the points that have a great impact on the classification results for further disturbance analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 It is a schematic diagram of the method flow of the present invention. DETAILED DESCRIPTION

[0023] See also Figure 1 This embodiment provides a method for generating adversarial samples, comprising the following steps:

[0024] Step S1: Input image I and standardize the image. The standardized image has the same size as the original image. All coordinates of the standardized image are within the range [LB, UB]. LB and UB are two constants, and LB < 0, UB > 0. Use T∈R l×w×h represents the space of all valid images that satisfy the above properties; for each I∈Τ, all coordinates in the image satisfy: (b,x,y)∈[l]×[w]×[h],I(b,x,y)∈[LB,UB];

[0025] Step S2, the classification label is C(I)∈{1,...,C}, p and r are perturbation coefficients, the side length of the image neighborhood search radius is 2d, the maximum number of iterations is R, and the number of pixels selected in each iteration is t;

[0026] Step S3: Randomly select 10% of the pixels and initialize the set (P x ,P y ), (P x ,P y ) i is a set of pixel positions; the first round (P x ,P y )0 is randomly generated; in each subsequent round, it is formed based on a set of pixel positions that were disturbed in the previous round; let (P x ,P y ) i-1 represents the middle pixel position of the disturbed area in round i-1, then

[0027] Step S4, traverse (P x ,P y ) pixels, perturb PRER(I,p,x,y) to obtain a new image set;

[0028] The perturbation method is PETR(I,p,x,y)=p×sign(I(*,x,y)), where sign is the sign function, defined as

[0029] Step S5: Calculate the probability score (I) of each image in the new image set predicting the original classification label; select t pixels with the largest probability to obtain a new pixel set (P x ,P y ); traverse(P x ,P y ), for (x,y)∈(P x ,P y ) neighborhood, perform perturbation RangeAdv(r,b,x,y), and update the original image I; the range perturbation method is

[0030] Step S6: If If the attack is successful, the attack ends; otherwise, the attack model is defined as NN, and the classification result of NN is: NN(I)=(o1,...,o c ), where o i is the probability of the image being identified as the i-th label; π(NN(I p ), k) are the topk labels of the classification of the model NN for the image I;

[0031] Step S7, traverse (P x ,P y ), with each pixel as the center, draw a square with a side length of 2d, and all points within the square are included (P x ,P y ), go to step S4.

[0032] The method is as follows:

[0033] 1. First, the normalization and denormalization functions are defined. For ease of processing, the data is normalized to between [-0.5, 0.5].

[0034] Normalization function:

[0035] normalize(im):

[0036] im=im–(min_+max_) / 2

[0037] im=im / (max_-min_)

[0038] LB=-1 / 2

[0039] UB=1 / 2

[0040] return im,LB,UB

[0041] Inverse normalization function:

[0042] unnormalize(im)

[0043] im=im*(max_-min_)

[0044] im=im+(min_+max_) / 2

[0045] return im

[0046] adv_img,LB,UB=normalizez(adv_img).

[0047] 2. Randomly select a number of pixels, the total number shall not exceed 10% of the total, and the maximum number shall not exceed 128.

[0048] Random_locations():

[0049] n=int(0.1*h*w)

[0050] n=min(n,128)

[0051] locations=np.random.permutation(h*w)[:n]

[0052] p_x = locations%w

[0053] p_y=location / / w

[0054] pxy=list(zip(p_x,p_y))

[0055] pxy = np.array(pxy)

[0056] returnpxy

[0057] Implementing the perturbation function RangeAdv

[0058] RangeAdv(r,Ibxy):

[0059] result = r * Ibxy

[0060] ifresult.any() <LB:

[0061] Result = result + (UB - LB)

[0062] elseifresult.any()>UB:

[0063] result=result–(UB-LB)

[0064] result = result.clip(LB,UB)

[0065] returnresult

[0066] Initialize the image and (P x ,P y )gather.

[0067] Ii=adv_img

[0068] PxPy = random_locations().

[0069] 3. From (P x ,P y ) randomly select up to 128 points from the set, traverse each point, perturb each point and generate a new image to obtain a new image set. For the new image set. Calculate each image in the new image combination to obtain the probability value of being classified as the original label.

[0070] fortry_timeinrange(R):

[0071] #Reorder, randomly select no more than 128 points

[0072] PxPy=PxPy[np.random.permutation(len(PxPy))[:128]]

[0073] L=[pert(Ii,p,x,y)forx,yinPxPy]

[0074] #Batch return prediction results to obtain the probability of the original image label

[0075] defscore(Its):

[0076] Its = np.stack(Its)

[0077] Its=unnormalize(Its)

[0078] scores=[self.model.predict(unnormalize(Ii))[original_label]forItinIts]

[0079] returnscores.

[0080] 4. Select the t points with the greatest influence to form a new (P x ,P y ) collection, np.argsort returns an ascending sort, so the last t items need to be taken.

[0081] scores=scores[L]

[0082] indices=np.argsort(scores)[:-t]

[0083] PxPy_star=PxPy[indeces].

[0084] 5. Traversal (P x ,P y ) set and perturb the original image at the same time.

[0085] Predict the newly generated images. If the classification label changes, the attack is successful. Otherwise, continue. x ,P y ) set, with each pixel as the center, draw a square with a side length of 2d, and all points within the square are included in the set (P x ,P y ).

[0086] PxPy=[(x,y)for_a,_binPxPy_star]

[0087] forxinrange(_a–d,_a+d+1)

[0088] foryinrange(_b–d,_b+d+1)]

[0089] PxPy=[(x,y)forx,yinPxPyif0<=x <wand0<=y<h]

[0090] PxPy=list(set(PxPy))

[0091] PxPy = np.narry(PxPy).

[0092] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above specific embodiments. The above specific embodiments and the description in the specification are only for further illustrating the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of the present invention to be protected is defined by the claims and their equivalents.

Claims

1. A method for generating adversarial samples, characterized in that: The following steps are included: Step S1: Input image I and standardize the image. The standardized image has the same size as the original image. All coordinates of the standardized image are within the range [LB, UB]. LB and UB are two constants, and LB < 0, UB > 0. Use T∈R l×w×h represents the space of all valid images that satisfy the above properties; for each I∈Τ, all coordinates in the image satisfy (b,x,y)∈[l]×[w]×[h],I(b,x,y)∈[LB,UB]; Step S2, the classification label is C(I)∈{1,...,C}, p and r are perturbation coefficients, the side length of the image neighborhood search radius is 2d, the maximum number of iterations is R, and the number of pixels selected in each iteration is t; Step S3: Randomly select 10% of the pixels and initialize the set (P x ,P y ), (P x ,P y ) i is a set of pixel positions; the first round (P x ,P y )0 is randomly generated; in each subsequent round, it is formed based on a set of pixel positions that were disturbed in the previous round; let (P x ,P y ) i-1 represents the middle pixel position of the disturbed area in round i-1, then Step S4, traverse (P x ,P y ) pixels, perturb PRER(I,p,x,y) to obtain a new image set; the perturbation method is PETR(I,p,x,y)=p×sign(I(*,x,y)), where sign is a sign function defined as Step S5: Calculate the probability score (I) of each image in the new image set predicting the original classification label; select t pixels with the largest probability to obtain a new pixel set (P x ,P y ); traverse(P x ,P y ), for (x,y)∈(P x ,P y ) neighborhood, perform perturbation RangeAdv(r,b,x,y), and update the original image I; the range perturbation method is Step S6: If If the attack is successful, the attack ends; otherwise, the attack model is defined as NN, and the classification result of NN is: NN(I)=(o1,...,o c ), where o i is the probability of the image being identified as the i-th label; π(NN(I p ), k) are the topk labels of the classification of the model NN for the image I; Step S7, traverse (P x ,P y ), with each pixel as the center, draw a square with a side length of 2d, and all points within the square are included (P x ,P y ), go to step S4.

2. The adversarial sample generation method according to claim 1, characterized in that: From (P x ,P y ) set, randomly select up to 128 points, traverse each point, perturb each point and generate a new image to obtain a new image set; calculate each image in the new image set to obtain the probability value of being classified as the original label.

3. The adversarial sample generation method according to claim 1, characterized in that: After normalizing the data, all coordinates are between [-0.5, 0.5].