How to disable dropout while prediction in keras?

前端 未结 4 688
我寻月下人不归
我寻月下人不归 2021-01-03 22:30

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

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

For testing,

4条回答
  •  囚心锁ツ
    2021-01-03 23:16

    You can change the dropout in a trained model (with dropout layers):

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

    In this way you don't have to train again the model!!!

提交回复
热议问题