如何在keras中进行预测时禁用辍学? [英] How to disable dropout while prediction in keras?

查看:496
本文介绍了如何在keras中进行预测时禁用辍学?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在keras的神经网络模型中使用了dropout.一点点的代码就像

I am using dropout in neural network model in keras. Little bit code is like

model.add(Dropout(0.5))
model.add(Dense(classes))

为了测试,我使用的是preds = model_1.predict_proba(image).

For testing, I am using preds = model_1.predict_proba(image).

但是,在测试 Dropout 时,他们也参与预测分数,这是不应该发生的.我进行了很多搜索以禁用退出功能,但尚未得到任何提示.

But while testing Dropout is also participating to predict the score which should not be happen. I search a lot to disable the dropout but didn't get any hint yet.

有人在解决在keras中测试时禁用 Dropout 的解决方案吗?

Do anyone have solution to disable the Dropout while testing in keras??

推荐答案

Keras默认执行此操作.在Keras中,在测试模式下将禁用辍学功能.您可以在此处查看代码并看到他们在训练中使用了丢弃的输入,而在测试时使用了实际输入.

Keras does this by default. In Keras dropout is disabled in test mode. You can look at the code here and see that they use the dropped input in training and the actual input while testing.

据我所知,您必须从各个层构建自己的训练函数,并指定训练标志以进行辍学预测(例如,不可能为预测函数指定训练标志).如果您要进行GAN,则这是一个问题,因为生成的训练图像和生成的测试图像之间存在差异,因此使用中间输出进行训练并且还对整个网络进行了训练.

As far as I know you have to build your own training function from the layers and specify the training flag to predict with dropout (e.g. its not possible to specify a training flag for the predict functions). This is a problem in case you want to do GANs, which use the intermediate output for training and also train the network as a whole, due to a divergence between generated training images and generated test images.

这篇关于如何在keras中进行预测时禁用辍学?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆