tensorflow - Keras 前向传递(带 dropout)

标签 tensorflow machine-learning keras dropout

我正在尝试使用 dropout 来获取 error estimates对于神经网络。

这涉及在训练后运行我的网络的几次前向传递,并激活 dropout。然而,在调用 model.predict() 时,Dropout 似乎并未被激活。这可以在 Keras 中完成吗?还是我必须在其他地方进行权重?

最佳答案

随机前向传递(在测试期间使用 dropout)可以使用 keras 后端函数来实现。假设您有一个经过训练的神经网络,名为 model:

from keras import backend as K

nb_MC_samples = 100
MC_output = K.function([model.layers[0].input, K.learning_phase()], [model.layers[-1].output])

learning_phase = True  # use dropout at test time
MC_samples = [MC_output([x_test, learning_phase])[0] for _ in xrange(nb_MC_samples)]
MC_samples = np.array(MC_samples)  # [#samples x batch size x #classes]

有关完整实现,请参阅以下内容 ipython notebook .

关于tensorflow - Keras 前向传递(带 dropout),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44351054/

相关文章:

python - 当我尝试使用 keras 标记我的 txt 字符串数组时出现参数错误

python - 如何使用现有 CNN 模型中的预训练权重在 Keras 中进行迁移学习?

tensorflow - tfrecord 文件的最佳大小

python - 如何在Python中找到实际的逻辑回归模型?

python - scikit-learn SelectPercentile TFIDF 数据特征缩减

python - 删除 NER 处的 B 和 I 标记

python - 随机搜索获取参数未实现

python - 导入tensorflow报错: terminate called after throwing an instance of 'Xbyak::Error'

python - 有没有办法反转 TensorFlow 中的图?

python - 如何修复 CNN Keras 中 Dense Layer 的输入大小?