Kiryu Sento
毕业设计5

毕业设计5

工作计划

Sparse Evolution Attack直接用到排名攻击直接改个攻击是否成功评估函数是不行的

  • 更改选择和生成初始种群的策略(突变方法不变)
  • 适应度函数参考MLDE的,能成功几个是几个
  • 数据集整理函数以及实验基本框架(记录实验数据之类的)

  • 扰动量过于大了,投影到L2 50的范围就会失效

  • 通过更改适应度评估函数,现在在200次查询的成功率达到了27/500的大小
  • 计划先慢慢提高查询次数上限看是否有明显提升,如果没有,很可能方法是无效的
  • 更改klh学长的实验代码框架,获取对照数据

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def fitness_eval(model, input, image, target_top):
# 适应度评估
clip_input = clip_perturbation(image, input, 50.)
outputs = model(clip_input)

ranking = torch.argsort(outputs, descending=True).cuda()
top_class = set(ranking[0][0:3].tolist())
ft = torch.sum(ranking[0][0:3]==target_top)
target_top = set(target_top.tolist())
fitness = len(top_class&target_top)
return fitness

def is_adversarial_rank1(model, input, target_top):
# 判断首3位rank1攻击是否成功

outputs = model(input)

ranking = torch.argsort(outputs, descending=True).cuda()
top_class = set(ranking[0][0:3].tolist())
target_top = set(target_top.tolist())
is_adv = top_class==target_top
return is_adv

需要的指标:扰动大小,最大查询次数


又更新了一下更新策略

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def init_distnfitness(original, x_pert, model, target_classes, fitness_min):
# initialize ditance & fitness
distance_pert = torch.norm(original-x_pert)
fitness=fitness_eval(model, x_pert, original, target_classes)
return distance_pert, fitness


def update(original, x_pert, model, target_classes, dist, fitness, V, k_worst, v_new):
distance_pert = torch.norm(original-x_pert)
fitness_pert=fitness_eval(model, x_pert, original, target_classes)
if fitness_pert>fitness[k_worst] or (fitness_pert==3 and distance_pert<dist[k_worst]):
fitness[k_worst] = fitness_pert
dist[k_worst] = distance_pert
V[k_worst] = v_new

return V, dist, fitness

扰动很难降到二范数<=50.的程度,少数会超过150,大部分是小于150的


因为成功率偏低,双更新了筛选策略

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def get_bestnworst(fitness, dist):
fitness_t = fitness.detach().clone()
dit_t = dist.detach().clone()
fitness_low = fitness<3
k_worst = torch.nonzero(fitness_low)
# print(k_worst)
if k_worst.numel() > 0:
k_worst = torch.argmin(torch.where(fitness_low, fitness, 0.))
else:
k_worst = torch.argmax(dist)
fitness_high = fitness>=3
k_best = torch.nonzero(fitness_high)
if k_best.numel() >= 2:
k_best = torch.argmin(torch.where(fitness_high, dist, torch.inf))
else:
k_best = torch.argmax(fitness)
return k_best, k_worst

现在的结果(只各跑了一次):

200代:l2=135+-, 成功率89.6上下

400代:l2=128+-,成功率91.4上下

800代:l2=116+-,成功率92.8上下

1000代:l2=110+-,成功率94.2上下

本文作者:Kiryu Sento
本文链接:https://wandernforte.github.io/kirameki/毕业设计5/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可