Monte-Carlo Dropout

Monte-Carlo Dropout(蒙特卡罗 dropout),简称 MC dropout。

一种从贝叶斯理论出发的 Dropout 理解方式,将 Dropout 解释为高斯过程的贝叶斯近似。

云里雾里的,理论证明看起来挺复杂,有兴趣可以参考论文:Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning. 以及这篇论文的 Appendix

但其实,MC dropout 用起来就简单了,不需要修改现有的神经网络模型,只需要神经网络模型中带 dropout 层,无论是标准的 dropout 还是其变种,如 drop-connect,都是可以的。

在训练的时候,MC dropout 表现形式和 dropout 没有什么区别,按照正常模型训练方式训练即可。

在测试的时候,在前向传播过程,神经网络的 dropout 是不能关闭的。这就是和平常使用的唯一的区别。

MC dropout 的 MC 体现在我们需要对同一个输入进行多次前向传播过程,这样在 dropout 的加持下可以得到“不同网络结构”的输出,将这些输出进行平均和统计方差,即可得到模型的预测结果及 uncertainty。而且,这个过程是可以并行的,所以在时间上可以等于进行一次前向传播。

神经网络产生的 softmax 概率不能表示 uncertainty?

其实我们在很多时候都拿了 softmax 的概率计算 uncertainty,比如主动学习查询策略中的 least confident、margin、entropy。在 entropy 策略下,softmax 的概率越均匀熵越大,我们就认为 uncertainty 越大;反之,在 softmax 某一维接近 1,其它都接近 0 时,uncertainty 最小。

但是,softmax 值并不能反应该样本分类结果的可靠程度。A model can be uncertain in its predictions even with a high softmax output. [1]

以 MNIST 分类为例,当模型在验证集上面效果很烂的时候,将一张图片输入到神经网络,我们仍然可以得到很高的 softmax 值,这个时候分类结果并不可靠;当模型在验证集上效果很好了,在测试集上甚至都很好,这个时候,我们将一张图片加入一些噪声,或者手写一个数字拍成照片,输入到网络中,这个时候得到一个较高的 softmax 值,我们就认为结果可靠吗?我们这个时候可以理解为,在已知的信息中,模型认为自己做的挺好,而模型本身并不能泛化到所有样本空间中去,对于它没有见过的数据,它的泛化能力可能不是那么强,这个时候模型仍然是以已知的信息对这个没有见过的数据有很强的判断(softmax 某一维值很大),当然有时候判断很好,但有时候判断可能就有误,而模型并不能给出对这个判断有多少 confidence。

而 MC dropout 可以给出一个预测值,并给出对这个预测值的 confidence,这也就是贝叶斯深度学习的优势所在。

MC dropout 示例代码

import tensorflow as tf
mnist = tf.keras.datasets.mnist (x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0 inp = tf.keras.layers.Input(shape=(28, 28))
x = tf.keras.layers.Flatten()(inp)
x = tf.keras.layers.Dense(512, activation=tf.nn.relu)(x)
x = tf.keras.layers.Dropout(0.5)(x, training=True) # dropout 在训练和测试时都将开着
out = tf.keras.layers.Dense(10, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inp, out) model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']) model.fit(x_train, y_train, epochs=3)
# 在测试过程,dropout 也是打开的,得到的结果将会有波动,而不是完全一致
for _ in range(10):
print(model.predict(x_test[:1]))

dropout 层一直处于打开的状态,测试过程重复进行多次。

References

[1] Gal, Y., & Ghahramani, Z. (2015). Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning. Retrieved from http://arxiv.org/abs/1506.02142

[2] Gal, Y., & Ghahramani, Z. (2015). Dropout as a Bayesian Approximation: Appendix. Retrieved from http://arxiv.org/abs/1506.02157

【实验笔记】深度学习中的两种不确定性(上)-- 张子杨

Dropout的前世与今生 -- 机器之心

Deep Bayesian Neural Networks. -- Stefano Cosentino

Monte-Carlo Dropout的更多相关文章

  1. Monte Carlo方法简介(转载)

    Monte Carlo方法简介(转载)       今天向大家介绍一下我现在主要做的这个东东. Monte Carlo方法又称为随机抽样技巧或统计实验方法,属于计算数学的一个分支,它是在上世纪四十年代 ...

  2. 增强学习(四) ----- 蒙特卡罗方法(Monte Carlo Methods)

    1. 蒙特卡罗方法的基本思想 蒙特卡罗方法又叫统计模拟方法,它使用随机数(或伪随机数)来解决计算的问题,是一类重要的数值计算方法.该方法的名字来源于世界著名的赌城蒙特卡罗,而蒙特卡罗方法正是以概率为基 ...

  3. PRML读书会第十一章 Sampling Methods(MCMC, Markov Chain Monte Carlo,细致平稳条件,Metropolis-Hastings,Gibbs Sampling,Slice Sampling,Hamiltonian MCMC)

    主讲人 网络上的尼采 (新浪微博: @Nietzsche_复杂网络机器学习) 网络上的尼采(813394698) 9:05:00  今天的主要内容:Markov Chain Monte Carlo,M ...

  4. Monte Carlo Approximations

    准备总结几篇关于 Markov Chain Monte Carlo 的笔记. 本系列笔记主要译自A Gentle Introduction to Markov Chain Monte Carlo (M ...

  5. (转)Markov Chain Monte Carlo

    Nice R Code Punning code better since 2013 RSS Blog Archives Guides Modules About Markov Chain Monte ...

  6. [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:

    http://www.cqt8.com/soft/html/723.html下载,官网下载 (转帖)1.定义: 蒙特卡洛(Monte Carlo)模拟是一种通过设定随机过程,反复生成时间序列,计算参数 ...

  7. Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)

    Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)  部分翻译自“Monte Carlo Tree Search and Its Applicati ...

  8. (转)Monte Carlo method 蒙特卡洛方法

    转载自:维基百科  蒙特卡洛方法 https://zh.wikipedia.org/wiki/%E8%92%99%E5%9C%B0%E5%8D%A1%E7%BE%85%E6%96%B9%E6%B3%9 ...

  9. Introduction To Monte Carlo Methods

    Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...

  10. 强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods)

    强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods) 学习笔记: Reinforcement Learning: An Introduction, Richard S ...

随机推荐

  1. SpringBoot 2 HTTP转HTTPS

    @Bean public TomcatServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat ...

  2. Flink 源码解析 —— 如何获取 ExecutionGraph ?

    https://t.zsxq.com/UnA2jIi 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Mac 上搭建 Flink 1.6. ...

  3. Java并发编程实战笔记—— 并发编程1

    1.如何创建并运行java线程 创建一个线程可以继承java的Thread类,或者实现Runnabe接口. public class thread { static class MyThread1 e ...

  4. struts的上传下载

    文件上传 添加jar包 commons-io-1.3.2.jar commons-fileupload-1.2.1.jar 前台页面 form表单 method值为post 添加"encty ...

  5. redis高可用之DNS篇

    1.  背景 例如,存在一套redis主从(主从节点在不同的主机上),应用程序通过主库的ip进行读写操作. 但是,主库一旦出现故障,虽然有从库,且从库提升为主库,但是应用程序如果想使用从库则必须修改配 ...

  6. springmvc异步处理

    好久没有写过博客了,都是看大牛的文章,略过~~ 突然感觉成长在于总结!废话不多说,开干 由于是公司项目,所以不方便给出代码,看图操作 在项目util目录下创建工具类TaskExecutorConfig ...

  7. java集合类的相关转换

    下面的的案例,基本上是以代码为主,文字的描述较少,后期有时间会继续添加. ArrayToList public void ArrayToList() { System.out.println(&quo ...

  8. C++7行代码实现求最大公约数

    最近在做奥赛题时碰到求最大公约数的问题,给出解决方案: int gcd(int a,int b){ int tmp = a%b; ){ return b; } else{ return gcd(b,t ...

  9. keras 学习笔记:从头开始构建网络处理 mnist

    全文参考 < 基于 python 的深度学习实战> import numpy as np from keras.datasets import mnist from keras.model ...

  10. Yii CGridView 之 SQL 语句

    在CGridView里,有时候需要用到复杂的查询时,可用 CSqlDataProvider替换CActiveDataProvider, CSqlDataProvider 可用复杂的查询语句,例子如下: ...