|
| 1 | + |
| 2 | +# Review of |
| 3 | +## ROBUST CONVOLUTIONAL NEURAL NETWORKS UNDER ADVERSARIAL NOISE |
| 4 | + |
| 5 | +https://arxiv.org/pdf/1511.06306.pdf |
| 6 | + |
| 7 | +## 요약 |
| 8 | + |
| 9 | +여러 연구 [CVPR 2017 https://arxiv.org/pdf/1610.08401.pdf] 들을 보면 CNN은 작은 perturbation ( adversarial examples )에 취약합니다. 위 논문은 adversarial noise에 robust한 CNN을 모델을 제안하였습니다. |
| 10 | + |
| 11 | +## 취약한 CNN (이미지 공격) |
| 12 | + |
| 13 | +### 1. Input Noise |
| 14 | + |
| 15 | +Image에 random noise ( 정규 분포 ) 를 추가함. |
| 16 | + |
| 17 | +$$ X_{ijk} = x_{ijk} + N(\mu x_{ijk},\sigma^2_N) $$ |
| 18 | + |
| 19 | +### 2. Universal Adversarial Perturbations - https://arxiv.org/pdf/1610.08401.pdf |
| 20 | + |
| 21 | +Perturbation은 '섭동'이라는 뜻인데, 천문학 기준으로는 원래의 궤도에서 벗어나게 하는 힘을 의미한다고 합니다. |
| 22 | + |
| 23 | +해당 논문에서는, 이미지 분류를 제대로 하지 못하게 하는 방해 요소라는 의미로 이해하면 좋겠습니다 |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +https://github.com/LTS4/universal/blob/master/python/universal_pert.py |
| 28 | + |
| 29 | +### Calc Perturbation |
| 30 | + |
| 31 | +최소한의 이미지 vector 이동을 통한 예측 오류 생성 |
| 32 | + |
| 33 | + |
| 34 | +```python |
| 35 | +def universal_perturbation(dataset, f, grads, delta=0.2, max_iter_uni = np.inf, xi=10, p=np.inf, num_classes=10, overshoot=0.02, max_iter_df=10): |
| 36 | + """ |
| 37 | + :param dataset: Images of size MxHxWxC (M: number of images) |
| 38 | + :param f: feedforward function (input: images, output: values of activation BEFORE softmax) |
| 39 | + :param grads: gradient functions with respect to input (as many gradients as classes). |
| 40 | + :param delta: controls the desired fooling rate (default = 80% fooling rate) |
| 41 | + :param max_iter_uni: optional other termination criterion (maximum number of iteration, default = np.inf) |
| 42 | + :param xi: controls the l_p magnitude of the perturbation (default = 10) |
| 43 | + :param p: norm to be used (FOR NOW, ONLY p = 2, and p = np.inf ARE ACCEPTED!) (default = np.inf) |
| 44 | + :param num_classes: num_classes (limits the number of classes to test against, by default = 10) |
| 45 | + :param overshoot: used as a termination criterion to prevent vanishing updates (default = 0.02). |
| 46 | + :param max_iter_df: maximum number of iterations for deepfool (default = 10) |
| 47 | + :return: the universal perturbation. |
| 48 | + """ |
| 49 | + |
| 50 | + v = 0 # image 이동 vector |
| 51 | + fooling_rate = 0.0 |
| 52 | + num_images = np.shape(dataset)[0] |
| 53 | + |
| 54 | + itr = 0 |
| 55 | + while fooling_rate < 1-delta and itr < max_iter_uni: # fooling rate가 어느정도 이상이 되거나, 많은 iteration을 돌았을 때 |
| 56 | + |
| 57 | + np.random.shuffle(dataset) # 데이터 set 섞기 |
| 58 | + |
| 59 | + |
| 60 | + #################################### 시작 ########################################## |
| 61 | + |
| 62 | + # Pertubation 계산 |
| 63 | + for k in range(0, num_images): |
| 64 | + cur_img = dataset[k:(k+1), :, :, :] |
| 65 | + |
| 66 | + # v가 image에 영향을 끼치지 못할 정도로 작은 경우, v value 업데이트 |
| 67 | + if int(np.argmax(np.array(f(cur_img)).flatten())) == int(np.argmax(np.array(f(cur_img+v)).flatten())): |
| 68 | + |
| 69 | + # Pertubation 계산 |
| 70 | + dr,iter,_,_ = deepfool(cur_img + v, f, grads, num_classes=num_classes, overshoot=overshoot, max_iter=max_iter_df) |
| 71 | + |
| 72 | + # v value 업데이트 |
| 73 | + if iter < max_iter_df-1: |
| 74 | + v = v + dr |
| 75 | + |
| 76 | + # Project on l_p ball |
| 77 | + v = proj_lp(v, xi, p) |
| 78 | + |
| 79 | + #################################### 끝 ########################################## |
| 80 | + |
| 81 | + itr = itr + 1 |
| 82 | + |
| 83 | + # Perturb the dataset with computed perturbation |
| 84 | + dataset_perturbed = dataset + v |
| 85 | + |
| 86 | + est_labels_orig = np.zeros((num_images)) |
| 87 | + est_labels_pert = np.zeros((num_images)) |
| 88 | + |
| 89 | + batch_size = 100 |
| 90 | + num_batches = np.int(np.ceil(np.float(num_images) / np.float(batch_size))) |
| 91 | + |
| 92 | + # Compute the estimated labels in batches |
| 93 | + for ii in range(0, num_batches): |
| 94 | + m = (ii * batch_size) |
| 95 | + M = min((ii+1)*batch_size, num_images) |
| 96 | + est_labels_orig[m:M] = np.argmax(f(dataset[m:M, :, :, :]), axis=1).flatten() |
| 97 | + est_labels_pert[m:M] = np.argmax(f(dataset_perturbed[m:M, :, :, :]), axis=1).flatten() |
| 98 | + |
| 99 | + # Compute the fooling rate |
| 100 | + fooling_rate = float(np.sum(est_labels_pert != est_labels_orig) / float(num_images)) |
| 101 | + print('FOOLING RATE = ', fooling_rate) |
| 102 | + |
| 103 | + return v |
| 104 | +``` |
| 105 | + |
| 106 | + |
| 107 | +```python |
| 108 | +def deepfool(image, f, grads, num_classes=10, overshoot=0.02, max_iter=50): |
| 109 | + |
| 110 | + """ |
| 111 | + :param image: Image of size HxWx3 |
| 112 | + :param f: feedforward function (input: images, output: values of activation BEFORE softmax). |
| 113 | + :param grads: gradient functions with respect to input (as many gradients as classes). |
| 114 | + :param num_classes: num_classes (limits the number of classes to test against, by default = 10) |
| 115 | + :param overshoot: used as a termination criterion to prevent vanishing updates (default = 0.02). |
| 116 | + :param max_iter: maximum number of iterations for deepfool (default = 10) |
| 117 | + :return: minimal perturbation that fools the classifier, number of iterations that it required, new estimated_label and perturbed image |
| 118 | + """ |
| 119 | + |
| 120 | + f_image = np.array(f(image)).flatten() |
| 121 | + I = (np.array(f_image)).flatten().argsort()[::-1] |
| 122 | + |
| 123 | + I = I[0:num_classes] |
| 124 | + label = I[0] # model의 데이터에 대한 예측 label |
| 125 | + |
| 126 | + input_shape = image.shape |
| 127 | + pert_image = image |
| 128 | + |
| 129 | + f_i = np.array(f(pert_image)).flatten() |
| 130 | + k_i = int(np.argmax(f_i)) # label이랑 다를게 없는 것 같은데...? |
| 131 | + |
| 132 | + w = np.zeros(input_shape) |
| 133 | + r_tot = np.zeros(input_shape) |
| 134 | + |
| 135 | + loop_i = 0 |
| 136 | + |
| 137 | + #################################### 시작 ########################################## |
| 138 | + while k_i == label and loop_i < max_iter: # 예측되는 label이 달라졌거나, iteration을 많이 돌렸으면 탈출! |
| 139 | + |
| 140 | + pert = np.inf |
| 141 | + gradients = np.asarray(grads(pert_image,I)) # input과 실제 label에 따른 변경될 gradient 계산 |
| 142 | + |
| 143 | + for k in range(1, num_classes): |
| 144 | + |
| 145 | + # set new w_k and new f_k |
| 146 | + w_k = gradients[k, :, :, :, :] - gradients[0, :, :, :, :] |
| 147 | + f_k = f_i[I[k]] - f_i[I[0]] |
| 148 | + pert_k = abs(f_k)/np.linalg.norm(w_k.flatten()) |
| 149 | + |
| 150 | + # determine which w_k to use |
| 151 | + if pert_k < pert: |
| 152 | + pert = pert_k |
| 153 | + w = w_k |
| 154 | + |
| 155 | + # compute r_i and r_tot |
| 156 | + r_i = pert * w / np.linalg.norm(w) |
| 157 | + r_tot = r_tot + r_i |
| 158 | + |
| 159 | + # perturbation 추가한 이미지 |
| 160 | + pert_image = image + (1+overshoot)*r_tot |
| 161 | + loop_i += 1 |
| 162 | + |
| 163 | + # label 계산을 다시 함 |
| 164 | + f_i = np.array(f(pert_image)).flatten() |
| 165 | + k_i = int(np.argmax(f_i)) |
| 166 | + #################################### 끝 ########################################## |
| 167 | + |
| 168 | + r_tot = (1+overshoot)*r_tot |
| 169 | + |
| 170 | + return r_tot, loop_i, k_i, pert_image |
| 171 | +``` |
| 172 | + |
| 173 | +### Perturbation Result |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +Universal Adversarial Pert.의 Remarkable 한 점은, 기존의 공격들은 공격된 이미지들을 포함하여 training 시키면 모델들의 robustness를 강화시킬수 있었으나 - UAP의 공격된 이미지는 training 시켜도 robustness가 강화되지 못했다는점! |
| 178 | + |
| 179 | +## 이미지 방어 전략 |
| 180 | + |
| 181 | +논문 - ROBUST CONVOLUTIONAL NEURAL NETWORKS UNDER ADVERSARIAL NOISE |
| 182 | +흠... 별건 없고 trained 된 모델을 feedfowarding할 때 input에 noise를 주고 뭔가 layer마다 stochastic한 성질은 주는건가? ㅎㅎ |
| 183 | + |
| 184 | +https://github.com/jhjin/stochastic-cnn/tree/master/demo |
| 185 | + |
| 186 | +### Input Noise Model |
| 187 | + |
| 188 | +위의 Input Noise를 줌 |
| 189 | + |
| 190 | +### 충격! 논문이 정말 별거 없었다.. |
| 191 | + |
| 192 | +Input에다가 Noise를 주면 뒤의 모든 layer들은 stochastic 해짐... 변하는건 없음! |
| 193 | + |
| 194 | +와... 논문의 Contribution이 feedfoward할 때 Input Noise만 준 것 뿐... 성능은 ㄱㅊㄱㅊ |
| 195 | + |
| 196 | +### Result |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | +# Image 방어 분야는 한-참 갈길이 멀다... |
0 commit comments