Adversarial Robustness - Theory and Practice

本文深入探讨了对抗性鲁棒性,包括对抗性例子的生成,如FGSM和PGD,以及如何通过对抗训练提高模型的抵抗力。在MINIST数据集上实验表明,对抗训练虽提升了对抗攻击的防御力,但会略微增加非对抗错误率。文章还讨论了外层最小化的优化策略,如凸松弛和局部搜索方法,以构建鲁棒模型。
摘要由CSDN通过智能技术生成


Adversarial Robustness - Theory and Practice

第一章 - Introduction to adversarial robustness

我运行Adversarial Robustness-Theory and Practice.introduction代码,加载resnet50,看到在注入噪音后,pig图像被算法误认为是airliner。

第二章 - linear models

(1) 加载MINIST数据集

(2) 对数据进行常规训练,TEST_ERR错误率仅仅0.04%.

(3) 开始进行对抗攻击,随机干扰数EPSILON =0.2

(4) 实行对抗攻击,发现TEST_ERR的错误率从之前的0.04%骤升到85%左右。

(5) 然后进行鲁棒训练,最核心的是MODEL(X.VIEW(X.SHAPE[0], -1))[:,0] - EPSILON*(2*Y.FLOAT()-1)*MODEL.WEIGHT.NORM(1)

(6) 鲁棒训练完成后,任何对抗攻击不会让TEST_ERROR高于2.5%。此时非对抗攻击得到的TEST_ERROR的错误率是0.3%左右(这个结果是大于之前的0.04%的)。这是鲁棒训练20个周期的结果,我测试了下,如果加大训练周期,并不会让结果更优。
也就是说进行鲁棒训练会提升抵抗对抗攻击的能力,但是同时会小幅度提升TEST_ERROR的比率。

第三章 - Adversarial examples, solving the inner maximization

1.非针对性攻击

主要方法是FGSM和PGD。PGD是迭代更新,比FGSM的迭代次数多。但是当梯度很小的时候,传统的PGD的效果也不好,于是出现the (normalized) steepest descent method.相对于传统PGD算法,它的delta.data = (delta + alpha*delta.grad.detach().sign()).clamp(-epsilon,epsilon)。这种改进的PGD的表现仍然受到目标内局部最优可能性的限制,虽然不可能完全避免局部最优,但可以通过随机重启来缓解这个问题。

2.针对性攻击(基于改进的PGD->the (normalized) steepest descent method)

最大化真实label的损失函数,并最小化目标label的损失函数,这相当于解决内部优化问题。下面是几种损失函数设计

(1)loss = (yp[:,y_targ] - yp.gather(1,y[:,None])[:,0]).sum()

缺点:仅仅让非零数字欺骗分类器。原因在于我们是the class logit for the zero minus the class logit for the true class. 但是我们实际上并不关心其他类的情况。所以我们可以修改损失函数为下面这种。

(2)loss = 2*yp[:,y_targ].sum() - yp.sum()

缺点:不能达到100%正确率。

(3) 占个位,这个不太懂。

3.组合优化解决内部最大问题

有一些寻找边界区间界限的方法,但是被轻微扰动后,区间界限上下浮动比较大,不实用。最终用的方法是混合整数线性规划策略。代码部分主要是利用cvxpy构建了很多constraints。

关于优化这部分内容不需要细看。如果细看的话,估计2年也看不完。大概知道做什么的就行了。

第四章 - Adversarial training, solving the outer minimization

1. 方案目标

The goal of the robust optimization formulation, therefore, is to ensure that the model cannot be attacked even if the adversary has full knowledge of the model.
In other words, no matter what attack an adversary uses, we want to have a model that performs well.

2. 可选择方案

2.1 local gradient-based search (providing a lower bound on the objective) 基于局部梯度的搜索
2.2 exact combinatorial optimization (exactly solving the objective) 精确的组合优化 (不实用)
2.3. convex relaxations (providing a provable upper bound on the objective) 凸松弛

但是经过分析,法2不实用,最终的可行方案是下面两个

2.1.Using lower bounds, and examples constructed via local search methods, to train an (empirically) adversarially robust classifier.
2.3Using convex upper bounds, to train a provably robust classifier.

3. 方案实施

The basic idea is to simply create and then incorporate adversarial examples into the training process
the question arises as to which adversarial examples we should train on?

4. 代码

4.1 加载minist数据集
4.2 初始化model_cnn
4.3 定义fgsm、pgd函数
4.4 定义标准训练函数、对抗攻击函数
4.5 进行联合训练(基于cnn)

  opt = optim.SGD(model_cnn.parameters(), lr=1e-1)
   for t in range(10):
       train_err, train_loss = epoch(train_loader, model_cnn, opt)
       test_err, test_loss = epoch(test_loader, model_cnn)
       adv_err, adv_loss = epoch_adversarial(test_loader, model_cnn, pgd_linf)
       if t == 4:
           for param_group in opt.param_groups:
               param_group["lr"] = 1e-2
       print(*("{:.6f}".format(i) for i in (train_err, test_err, adv_err)), sep="\t")
   	
   torch.save(model_cnn.state_dict(), "model_cnn.pt") 

So as we saw before, the clean error is quite low, but the adversarial error is quite high (and actually goes up as we train the model more). Let’s now do the same thing, but with adversarial training.
4.6 做一些happy的事情

opt = optim.SGD(model_cnn_robust.parameters(), lr=1e-1)
for t in range(10):
    train_err, train_loss = epoch_adversarial(train_loader, model_cnn_robust, pgd_linf, opt)
    test_err, test_loss = epoch(test_loader, model_cnn_robust)
    adv_err, adv_loss = epoch_adversarial(test_loader, model_cnn_robust, pgd_linf)
    if t == 4:
        for param_group in opt.param_groups:
            param_group["lr"] = 1e-2
    print(*("{:.6f}".format(i) for i in (train_err, test_err, adv_err)), sep="\t")
torch.save(model_cnn_robust.state_dict(), "model_cnn_robust.pt")

pretty good!

4.7 对比两个不同的cnn

  model_cnn_robust = nn.Sequential(nn.Conv2d(1, 32, 3, padding=1), nn.ReLU(),
                                    nn.Conv2d(32, 32, 3, padding=1, stride=2), nn.ReLU(),
                                    nn.Conv2d
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Video Tracking provides a comprehensive treatment of the fundamental aspects of algorithm and application development for the task of estimating, over time, the position of objects of interest seen through cameras. Starting from the general problem definition and a review of existing and emerging video tracking applications, the book discusses popular methods, such as those based on correlation and gradient-descent. Using practical examples, the reader is introduced to the advantages and limitations of deterministic approaches, and is then guided toward more advanced video tracking solutions, such as those based on the Bayes’ recursive framework and on Random Finite Sets. Key features: Discusses the design choices and implementation issues required to turn the underlying mathematical models into a real-world effective tracking systems. Provides block diagrams and simil-code implementation of the algorithms. Reviews methods to evaluate the performance of video trackers – this is identified as a major problem by end-users. The book aims to help researchers and practitioners develop techniques and solutions based on the potential of video tracking applications. The design methodologies discussed throughout the book provide guidelines for developers in the industry working on vision-based applications. The book may also serve as a reference for engineering and computer science graduate students involved in vision, robotics, human-computer interaction, smart environments and virtual reality programmes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值