Keras是否可以在训练和测试/验证阶段自动识别Drop和BatchNorm? [英] Can Keras automatically recognize the Drop and BatchNorm in train and test/validate phases?

查看:620
本文介绍了Keras是否可以在训练和测试/验证阶段自动识别Drop和BatchNorm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经是Tensorflow用户,在tensorflow中,我必须显式对待Drop和BatchNorm.例如,在测试/验证阶段,必须将丢弃率"设置为1,并指定BatchNorm的训练标志.

I have been a Tensorflow user, In tensorflow, I must explicitly treat the Drop and BatchNorm. For example, in test/validate phases, the Drop rate must be set to be 1, and specifilize the training flag for BatchNorm.

我的问题是:Keras可以在训练和测试/验证阶段自动识别Drop和BatchNorm吗?例如,如果我使用model.predict(),Keras会知道我正在测试/验证中,因此它将自动处理Drop和BatchNorm?

My question is: Can Keras automatically recognize the Drop and BatchNorm in train and test/validate phases? For example, if I use the model.predict(), Keras will know I am in the pjhase of test/validate, so it automatically process the Drop and BatchNorm?

B.T.W.,在验证/测试阶段,Keras将Dropout的速率设置为0,这与Tensorflow中的设置相反.在Tensorflow中,掉落率将设置为1.

B.T.W., Keras will set the rate to be 0 for Dropout when in validate/test phases, which is contrast to it in Tensorflow. In Tensorflow, Drop rate will set to be 1.

推荐答案

是的,Keras已经在内部跟踪学习/测试阶段,它通过一个称为learning_phase的内部变量来完成该功能,在测试时将其设置为零,并将其设置为一个训练时.

Yes, Keras already tracks the learning/testing phases internally, it does it through an internal variable called learning_phase, which is set to zero when testing, and to one when training.

您可以将该变量与keras.backend函数learning_phase()set_learning_phase(value)进行交互,这些函数已完全记录

You can interact this variable with keras.backend functions learning_phase() and set_learning_phase(value) which are fully documented.

这篇关于Keras是否可以在训练和测试/验证阶段自动识别Drop和BatchNorm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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