简体   繁体   中英

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. Is that right,or need some special codes to compute the BN after training like using SegNet in Caffe?

No, you don't need to do anything special when using BatchNormalization or Dropout layers. Keras already tracks the learning/testing phases, so when using predict or predict_classes , it does the right thing.

You do not even need to set the learning phase manually, Keras already does it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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