Keras: how to use dropout at train and test phase?

2019-08-20 04:30发布

问题:

Is it possible to use dropout at train and test phase in Keras?

Like described here: https://github.com/soumith/ganhacks#17-use-dropouts-in-g-in-both-train-and-test-phase

回答1:

Sure, you can set training argument to True when calling the Dropout layer. In this way, dropout would be applied in both training and test phases:

drp_output = Dropout(rate)(inputs, training=True)  # dropout would be active in train and test phases


回答2:

You don't want to use Dropout in Test phase.

Dropout is a technique used to force neurons to be more independent each other: each neuron will be deactivate with the probability that you set, but only in the training phase.

In the Test phase you keep all the neurons working.

More details here and here