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. 【转】C++文件读写详解(ofstream,ifstream,fstream)

    转:http://blog.csdn.net/kingstar158/article/details/6859379 摘要:具体用法,上面链接中,文章写的很详细,讲解ofstream,ifstream ...

  2. Spring入门编程问题集锦Top10

    我写的一篇文章,希望对spring初学者有所帮助: 1.如何学习Spring? 你可以通过下列途径学习spring: ①. spring下载包中doc目录下的MVC-step-by-step和samp ...

  3. JAVA基础知识(二):List接口、ArrayList类和LinkedList类

    List接口继承了Collection接口,位于java.util包中.它包含Collection接口的所有方法,外加其他一些方法(具体实现参考源码),比较重要的有: anyType get(int ...

  4. Element UI系列:Select下拉框实现默认选择

    实现的主要关键点在于 v-mode 所绑定的值,必须是 options 数组中对应的 value 值

  5. 最简单的DWR例子

    什么是DWR? DWR是一个Open Source的 java项目.DWR可以让JavaScript调用运行在Web服务器里面的JAVA程序.简单一点或者专业一点就是Easy AJAX for JAV ...

  6. Web 字体 font-family 再探秘

    之前写过一篇关于Web字体简介及使用技巧的文章: 你该知道的字体 font-family. 该篇文章基本没有太多移动端的字体选择及分析.并且过了这么久,如今的 Web 字体又有了一些新的东西,遂有此文 ...

  7. SAP-采购订单跟踪报表

    *&---------------------------------------------------------------------**& Report ZMM_CGDDFX ...

  8. cs231n官方note笔记

    本文记录官方note中比较新颖和有价值的观点(从反向传播开始) 一 反向传播 1 “反向传播是一个优美的局部过程.在整个计算线路图中,每个门单元都会得到一些输入并立即计算两个东西:1. 这个门的输出值 ...

  9. Android常用库源码解析

    图片加载框架比较 共同优点 都对多级缓存.线程池.缓存算法做了处理 自适应程度高,根据系统性能初始化缓存配置.系统信息变更后动态调整策略.比如根据 CPU 核数确定最大并发数,根据可用内存确定内存缓存 ...

  10. loging日志的使用

    2.日志: 记住怎么使用就好了 自己定义日志开始 import logging logger = logging.getLogger() # 创建一个logger fh = logging.FileH ...