Monte-Carlo Dropout
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的更多相关文章
- Monte Carlo方法简介(转载)
Monte Carlo方法简介(转载) 今天向大家介绍一下我现在主要做的这个东东. Monte Carlo方法又称为随机抽样技巧或统计实验方法,属于计算数学的一个分支,它是在上世纪四十年代 ...
- 增强学习(四) ----- 蒙特卡罗方法(Monte Carlo Methods)
1. 蒙特卡罗方法的基本思想 蒙特卡罗方法又叫统计模拟方法,它使用随机数(或伪随机数)来解决计算的问题,是一类重要的数值计算方法.该方法的名字来源于世界著名的赌城蒙特卡罗,而蒙特卡罗方法正是以概率为基 ...
- 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 ...
- Monte Carlo Approximations
准备总结几篇关于 Markov Chain Monte Carlo 的笔记. 本系列笔记主要译自A Gentle Introduction to Markov Chain Monte Carlo (M ...
- (转)Markov Chain Monte Carlo
Nice R Code Punning code better since 2013 RSS Blog Archives Guides Modules About Markov Chain Monte ...
- [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:
http://www.cqt8.com/soft/html/723.html下载,官网下载 (转帖)1.定义: 蒙特卡洛(Monte Carlo)模拟是一种通过设定随机过程,反复生成时间序列,计算参数 ...
- Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)
Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介) 部分翻译自“Monte Carlo Tree Search and Its Applicati ...
- (转)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 ...
- Introduction To Monte Carlo Methods
Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...
- 强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods)
强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods) 学习笔记: Reinforcement Learning: An Introduction, Richard S ...
随机推荐
- 用vue2.0+vuex+vue-router+element-ui+mockjs实现后台管理系统的实践探索
A magical vue element touzi admin. 效果演示地址 更多demo展示 分支说明 master分支:前后端统一开发的版本:可以用于学习nodejs+mongodb+exp ...
- BFS DFS模板
转载于https://blog.csdn.net/alalalalalqp/article/details/9155419 BFS模板: #include<cstdio> #include ...
- Pandas 库之 DataFrame
How to use DataFrame ? 简介 创建 DataFrame 查看与筛选数据:行列选取 DataFrame 数据操作:增删改 一.About DataFrame DataFrame 是 ...
- Vsftp服务器配置文件详解
vsftp软件是我们常见的FTP服务器搭建软件,所有的配置都是基于vsftpd.conf这个配置文件的.vsftpd.conf里面主要包括安全配置,传输,用户还有权限等相关的选项.现在我们讲解下关于V ...
- Spring Boot + Security + JWT 实现Token验证+多Provider——登录系统
首先呢就是需求: 1.账号.密码进行第一次登录,获得token,之后的每次请求都在请求头里加上这个token就不用带账号.密码或是session了. 2.用户有两种类型,具体表现在数据库中存用户信息时 ...
- exe4j打包--jar打包exe
本文重点介绍如何将我们写的java代码打包成在电脑上可以运行的exe文件.这里只介绍直接打包成exe的方法,至于打包成exe安装包下节介绍 test 软件准备 exe4j集合包下载地址(下节内容也在这 ...
- Android——倒计时跳转+sharedpreferences
public class MainActivity extends Activity { // 3秒钟后,从图1跳转到图2(10) private Handler handler=new Handle ...
- springmvc异步处理
好久没有写过博客了,都是看大牛的文章,略过~~ 突然感觉成长在于总结!废话不多说,开干 由于是公司项目,所以不方便给出代码,看图操作 在项目util目录下创建工具类TaskExecutorConfig ...
- 贪心算法-过河问题 pojo1700
过桥问题: 黑夜,只有一只手电筒 A过桥需要1s B过桥需要3s C过桥需要5s D过桥需要8s E过桥需要12s 求最小过桥时间 贪心算法: 从最大的开始过去,最小的两个做为辅助. 假如左岸人数为2 ...
- MySQL隔离性及Spring事务
一.数据库事务ACID特性 必须要掌握事务的4个特性,其中事务的隔离性之于MySQL,对应4级隔离级别. 原子性(Atomicity): 事务中的所有原子操作,要么都能成功完成,要么都不完成,不能停滞 ...