简体   繁体   English

在Keras中进行归一化或辍学训练时,如何预测?

[英]How to do predict when trained with Normalization or dropout layer in Keras?

I trained a model with Normalization layer. 我用归一化层训练了一个模型。 The code is as this: 代码是这样的:

In training phase: 在训练阶段:

model=Sequential()
model.add()

...

k.set_learning_phase(1)
ModelCheckpoint(weights_file)
model.fit()

In inference time: 推断时间:

k.set_learning_phase(0)
model.load_weights(weights_file)
model.predict_classes()

...

The version of Keras:2.0.8. Keras版本:2.0.8。 Is that right,or need some special codes to compute the BN after training like using SegNet in Caffe? 是这样吗,或者像在Caffe中使用SegNet一样在训练后需要一些特殊的代码来计算BN?

No, you don't need to do anything special when using BatchNormalization or Dropout layers. 不,使用BatchNormalization或Dropout图层时,您不需要做任何特殊的事情。 Keras already tracks the learning/testing phases, so when using predict or predict_classes , it does the right thing. Keras已经跟踪了学习/测试阶段,因此在使用predictpredict_classes ,它做对了。

You do not even need to set the learning phase manually, Keras already does it. 您甚至不需要手动设置学习阶段,Keras已经做到了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM