Kernel Density (KD)

Feinman R., Curtin R. R., Shintre S. and Gardner A. B. Detecting Adversarial Samples from Artifacts. arXiv preprint arXiv:1703.00410, 2017.

原文代码

作者认为普通样本的特征和对抗样本的特征位于不同的流形中, 故可以通过密度估计的方法, 估计出普通样本的密度函数, 然后求得样本各自的置信度, 选择合适的阈值(通过ROC-AUC之类的), 便有了区分普通样本和对抗样本的方法.

假设

\[z = h(x) \in \mathbb{R}^d.
\]

为将样本\(x\)提取为特征\(z\)

  1. 选取合适的样本数目\(x_1, \cdots, x_N\);
  2. 提取特征\(z_1, \cdots, z_N\);
  3. 构建核密度估计函数:
\[\hat{f}(x) = \frac{1}{N} \sum_{i=1}^N k_{\sigma}(z_i, h(x)), \\
k_{\sigma}(z, z') = \frac{1}{(2\pi)^{\frac{d}{2}}\sigma^d}\exp (-\frac{\|z' - z\|^2}{2\sigma^2}).
\]

选择合适的阈值\(t\), 对于样本\(x\), 判定其为对抗样本, 若\(\hat{f}(x) < t\).

有些时候, 可以对每一类构建一个\(\hat{f}(x)\), 但这个情况也就只能用在ROC-AUC了.

Local Intrinsic Dimensionality (LID)

LID

Gaussian Discriminant Analysis (GDA)

Lee K., Lee K., Lee H. and Shin J. A simple unified framework for detecting out-of-distribution samples and adversarial attacks. In Advances in Neural Information Processing Systems (NIPS), 2018.

原文代码

作者假设特征\(z=h(x)\)(所属类别为\(c\))满足后验分布:

\[z|y=c \sim \mathcal{N}(\mu_c, \Sigma),
\]

\[p(h(x)|y=c) = \mathcal{N}(h(x)|\mu_c, \Sigma),
\]

注意到对于不同的\(c\), 协方差矩阵\(\Sigma\)是一致的(这个假设是为了便于直接用于分类, 但是与detection无关, 便不多赘述).

均值和协方差矩阵通过如下方式估计:

\[\hat{\mu}_c = \frac{1}{N_c} \sum_{i:y_i=c}h(x_i), \: \widehat{\Sigma} = \frac{1}{N}\sum_c \sum_{i:y_i=c}(h(x_i) - \hat{\mu}_c) (h(x_i) - \hat{\mu}_c)^T.
\]

故可以用

\[\hat{f}(x) := \max_c \mathcal{N}(h(x)| \hat{\mu}_c, \widehat{\Sigma}),
\]

来区分\(x\)是否为abnormal的样本(对抗的或者偏离训练分布的样本).

在文中用的是log化(且去掉比例系数)的指标:

\[M(x) = \max_c -(h(x) - \hat{\mu}_c)^T \widehat{\Sigma}(h(x) - \hat{\mu}_c).
\]

改方法可以进一步拓展(实际上光用这个指标看实验结果似乎并不理想):

  1. Input pre-processing:

对于输入的样本进行如下变换:

\[\hat{x} = x + \epsilon \mathrm{sign}(\nabla_x M(x)).
\]

有点像fgsm生成对抗样本, 但感觉这么做的原因是让\(\hat{f}(x)\)之间的区别大一点.

  1. Feature ensemble:

即对不同层的特征\(h_l(x)\)都进行如上的操作, 然后得到\(\hat{f}_1, \cdots, \hat{f}_L\), 并通过SVM来训练得到权重\(\alpha_l\), 最后的score为

\[\sum_l \alpha \hat{f}_l(x).
\]

注: 文中实际为\(M_l(x)\).

Gaussian Mixture Model (GMM)

Zheng Z. and Hong P. Robust detection of adversarial attacks by modeling the intrinsic properties of deep neural networks. In Advances in Neural Information Processing Systems (NIPS), 2018.

类似的, 对于特征\(z=h(x)\), 假设其服从GMM:

\[p(h(x)|y=c;\theta) = \sum_{k=1}^K w_i \mathcal{N}(h(x)|\mu_{ck}, \Sigma_{ck}),
\]

并用EM算法来估计.

注: 对每一个类别都需要估计一个GMM模型.

于是

\[\hat{f}_c(x) = p(h(x)|y=c;\theta),
\]

当其小于给定的threshold的时候, 便认为其不属于类别\(c\).

问: 所以当所有的\(c\)都被拒绝的时候, 就可以认为是对抗样本了?

SelectiveNet

Geilman Y., El-Yaniv R. SelectiveNet: A deep neural network with an integrated reject option. In International Conference on Machine Learning (ICML), 2019.

原文代码

本文的模型解释起来有点复杂, 在一个普通的判别网络\(f\)的基础上:

\[(f, g)(x) :=
\left \{
\begin{array}{ll}
f(x) & \text{if } g(x) = 1, \\
\text{don't know} & \text{if } g(x) = 0.
\end{array}
\right .
\]

其中\(g\)是一个用来选择是否判断的模块.

作者给出了两个指标:

Coverage:

\[\phi(g) := E_P [g(x)],
\]

以及

Selective Risk:

\[R(f, g) := \frac{E_P[\ell(f(x), y) g(x)]}{\phi(g)}.
\]

Coverage不能太低, 因为如果全部拒绝判断模型就没有意义了, 然后\(R(f, g)\)自然是越低越好, 但是注意到, 虽然一味拒绝回答能够使得分子接近0, 但是分母也会接近0, 所以需要一个平衡.

二者的经验估计如下:

\[\hat{r}(f,g|S_N) := \frac{\frac{1}{N}\sum_{i=1}^N \ell(f(x_i), y_i)g(x_i)}{\phi(g|S_N)}, \\
\phi(g|S_N):= \frac{1}{N}\sum_{i=1}^N g(x_i).
\]

注: 在实际使用中, \(g\)的取值往往在\([0, 1]\)间, 此时可以选取threshold t来选择是否判断.

作者设计了一个结构如下:

其中:

Prediction: \(f\);

Selection: \(g\);

Auxiliary: \(h\), 作者说此为别的任务来帮助训练的.

最后的损失:

\[\mathcal{L} = \alpha \mathcal{L}_{(f, g)} + (1 - \alpha) \mathcal{L}_h \\
\mathcal{L}_{(f, g)} = \hat{r}_{\ell} (f, g|S_N) + \lambda \Psi(c - \hat{\phi}(g | S_N)) \\
\Psi(a) = \max(0, a)^2 \\
\mathcal{L}_h = \hat{r}(h|S_N) = \frac{1}{N}\sum_{i=1}^N \ell (h(x_i), y_i).
\]

Combined Abstention Robustness Learning (CARL)

Laidlaw C., Feizi S. Playing it safe: adversarial robustness with an abstain option. arXiv preprint arXiv:1911.11253, 2019.

原文代码

假设\(f\)将样本\(x\)映射为\(\mathcal{Y} \bigcup \{a\}\), 其中\(a\)表示弃权(don't know).

则我们可以定义:

\[\mathcal{R}_{nat} (f) := \mathbb{E}_{(x, y) \sim \mathcal{D}} \mathbf{1}\{f(x) \not = y\} \\
\mathcal{R}_{adv}(f) := \mathbb{E}_{(x, y) \sim \mathcal{D}} \max_{\tilde{x} \in \mathcal{B}_{\epsilon}(x)} \mathbf{1}\{f(\tilde{x} \not = y \text{ and } f(\tilde{x}) \not = a\}.
\]

很自然的, 我们可以通过优化下列损失

\[\mathcal{R}(f) = \mathcal{R}_{nat}(f) + c \mathcal{R}_{adv}(f),
\]

来获得一个带有弃权功能的判别器. 并且通过权重\(c\)我们可以选择更好的natural精度或者更保守但更加安全的策略.

直接优化上面的损失是困难的, 故选择损失来替换. 作者采用普通的交叉熵损失来代替nat:

\[\mathcal{L}_{nat}(f) = \mathbb{E}_{(x, y) \sim \mathcal{D}} -\log p_y(x),
\]

用下列之一替代adv:

\[\mathcal{L}_{adv}(f) \mathbb{E}_{(x, y) \sim \mathcal{D}} \max_{\tilde{x} \in \mathcal{B}_{\epsilon}(x)} \ell(f, \tilde{x}, y), \\
\ell = \{\ell^{(1)}, \ell^{(2)}\} \\
\ell^{(1)} = -\log (p_y (\tilde{x}) + p_a (\tilde{x})) \\
\ell^{(2)} = (-\log (p_y (\tilde{x})) \cdot (-\log p_a (\tilde{x})) \\
\]

Adversarial Training with a Rejection Option

Kato M., Cui Z., Fukuhara Y. ATRO: Adversarial training with a rejection option. arXiv preprint arXiv:2010.12905, 2020.

凸relax.

Energy-based Out-of-distribution Detection

Liu W., Wang X., Owens J. D., Li Y. Energy-based out-of-distribution detection. In Advances in Neural Information Processing Systems (NIPS), 2020.

普通的softmax分类网络可以从energy-based model的角度考虑:

\[p(y|x) = \frac{e^{-E(x, y) / T}}{\int_{y'}e^{-E(x, y') / T}},\\
E(x, y) = -f_y(x), \\
\]

Helmholtz free energy:

\[E(x;f):=-T \cdot \log \int_{y'}e^{-E(x, y') / T} = -T \cdot \log \sum_{i}^K e^{f_i(x)}/T.
\]

实际上, 通过\(E(x;f)\)我们可以构建\(x\)的能量模型:

\[p(x) = \frac{e^{-E(x;f)/T}}{\int_x e^{-E(x;f)/T}},
\]

故我们可以通过\(p(x)\)来判断一个样本是不是OOD的.

特别的, 由于对于所有的\(x\)

\[Z = \int_x e^{-E(x;f)/T}
\]

都是一致的, 所以我们只需要比较

\[e^{-E(x;f)/T}
\]

的大小就可以了.

特别的, 作者指出为什么用\(p(y|x)\)来作为判断是否OOD的依据不合适:

\[\begin{array}{ll}
\log \max_y p(y|x) &= \log \max_y \frac{e^{f_y(x)}}{\sum_i e^{f_i(x)}} \\
&= \log \frac{e^{f_{\max}(x)}}{\sum_i e^{f_i(x)}} \\
&= E(x;f(x) - f^{\max}(x)) \\
&= E(x;f) + f^{max}(x) \\
&= -\log p(x) + f^{max}(x) - \log Z \\
&\not\propto -\log p(x).
\end{array}
\]

WOW!

Confidence-Calibrated Adversarial Training: Generalizing to Unseen Attacks (CCAT)

Stutz D., Hein M. and Schiele B. Confidence-calibrated adversarial training: generalizing to unseen attacks. In International Conference on Machine Learning (ICML), 2020.

原文代码

假设\(f(x)\)为预测的概率向量, CCAT通过如下算法优化:

  1. 输入: \((x_1, y_1), \cdots, (x_B, y_B)\);
  2. 将其中一半用于对抗训练, 一半用于普通训练:
\[\min \quad \sum_{b=1}^{B/2} \mathcal{L}(f(\tilde{x}_b, \tilde{y}_b)) + \sum_{b=B/2+1}^B \mathcal{L}(f(x_b), y_b).
\]
  1. 其中
\[\tilde{x}_b = x_b + \delta_b, \\
\tilde{y}_b = \lambda(\delta_b) \text{ one\_hot}(y_b) + (1 - \lambda(\delta_b)) \frac{1}{K}, \\
\delta_b = \mathop{\arg \max} \limits_{\delta_{\infty} \le \epsilon} \max_{k \not= y_b} f_k(x_b + \delta), \\
\lambda (\delta_b) := (1 - \min(1, \frac{\|\delta_b\|_{\infty}}{\epsilon}))^{\rho}. \\
\]

\(\tilde{y}\)是真实标签和均匀分布的一个凸组合, 这个还是挺有道理的.

最后, 倘若如果

\[\max_k f_k(x),
\]

即置信度比较小的话, 拒绝判断(这个可靠的原因是目标函数让对抗样本趋于均匀分布).

Adversarial Detection methods的更多相关文章

  1. 论文解读(ARVGA)《Learning Graph Embedding with Adversarial Training Methods》

    论文信息 论文标题:Learning Graph Embedding with Adversarial Training Methods论文作者:Shirui Pan, Ruiqi Hu, Sai-f ...

  2. [转]Jailbreak Detection Methods

    Source: http://blog.spiderlabs.com/2014/10/jailbreak-detection-methods.html Many iOS applications co ...

  3. 生成对抗网络资源 Adversarial Nets Papers

    来源:https://github.com/zhangqianhui/AdversarialNetsPapers AdversarialNetsPapers The classical Papers ...

  4. CVPR 2011 Global contrast based salient region detection

    Two salient region detection methods are proposed in this paper: HC AND RC HC: Histogram based contr ...

  5. 文本分类实战(七)—— Adversarial LSTM模型

    1 大纲概述 文本分类这个系列将会有十篇左右,包括基于word2vec预训练的文本分类,与及基于最新的预训练模型(ELMo,BERT等)的文本分类.总共有以下系列: word2vec预训练词向量 te ...

  6. Anomaly Detection

    数据集中的异常数据通常被成为异常点.离群点或孤立点等,典型特征是这些数据的特征或规则与大多数数据不一致,呈现出“异常”的特点,而检测这些数据的方法被称为异常检测. 异常数据根据原始数据集的不同可以分为 ...

  7. PP: Time series clustering via community detection in Networks

    Improvement can be done in fulture:1. the algorithm of constructing network from distance matrix. 2. ...

  8. (转) AdversarialNetsPapers

      本文转自:https://github.com/zhangqianhui/AdversarialNetsPapers AdversarialNetsPapers The classical Pap ...

  9. [转]GAN论文集

    really-awesome-gan A list of papers and other resources on General Adversarial (Neural) Networks. Th ...

随机推荐

  1. 日常Java 2021/10/18

    Vecter类实现了一个动态数组,不同于ArrayList的是,Vecter是同步访问的, Vecter主要用在事先不知道数组的大小或可以改变大小的数组 Vecter类支持多种构造方法:Vecter( ...

  2. Hadoop org.apache.hadoop.util.DiskChecker$DiskErrorException问题等价解决linux磁盘不足解决问题排查

    org.apache.hadoop.util.DiskChecker$DiskErrorException问题等价解决linux磁盘不足解决问题排查 解决"/dev/mapper/cento ...

  3. Learning Spark中文版--第五章--加载保存数据(1)

      开发工程师和数据科学家都会受益于本章的部分内容.工程师可能希望探索更多的输出格式,看看有没有一些适合他们下游用户的格式.数据科学家可能会更关注他们已经使用的数据格式. Motivation   我 ...

  4. Spark基础:(五)Spark编程进阶

    共享变量 (1)累加器:是用来对信息进行聚合的,同时也是Spark中提供的一种分布式的变量机制,其原理类似于mapreduce,即分布式的改变,然后聚合这些改变.累加器的一个常见用途是在调试时对作业执 ...

  5. 在隐藏导航栏的控制器中,调用UIIMagePickerController,出现导航栏变透明的问题

    在隐藏导航栏的控制器中,调用UIIMagePickerController,出现导航栏变透明的问题 解决办法 #pragma mark - UIImagePickerController Delega ...

  6. HUD总结

    HUD 指示器/HUD/遮盖/蒙板 半透明的指示器如何实现 指示器的alpha = 1.0; 指示器的背景色是半透明的 1. 创建颜色 直接创建对应的颜色 + (UIColor *)blackColo ...

  7. 二叉搜索树、平衡二叉树、红黑树、B树、B+树

    完全二叉树: 空树不是完全二叉树,叶子结点只能出现在最下层和次下层,且最下层的叶子结点集中在树的左部.如果遇到一个结点,左孩子不为空,右孩子为空:或者左右孩子都为空:则该节点之后的队列中的结点都为叶子 ...

  8. Python——连接数据库操作

    一.数据库基础用法 要先配置环境变量,然后cmd安装:pip install pymysql 1.连接MySQL,并创建wzg库 #引入decimal模块 import pymysql #连接数据库 ...

  9. 00 - Vue3 UI Framework - 阅读辅助列表

    阅读列表 01 - Vue3 UI Framework - 开始 02 - Vue3 UI Framework - 顶部边栏 03 - Vue3 UI Framework - 首页 04 - Vue3 ...

  10. 如何在子线程中更新UI

    一:报错情况 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that creat ...