Keras: how to set learning phase after model loading
<p>I faced with problem when I try to train pre-trained model loaded from json config + weights file.</p>

<p>I use following code (simplified):</p>

<pre><code>from keras.utils.layer_utils import layer_from_config    
with open("config.json", "rb") as f:
    config = json.loads(f.read())
    model = layer_from_config(config)

model.load_weights("weights.net")

history = model.fit(batch, target, verbose=1, 
                    validation_data=(test_batch, test_target), shuffle=True)
</code></pre>

<p>And I got following exception:</p>

<blockquote>
  <p>theano.gof.fg.MissingInputError: ("An input of the graph, used to
  compute DimShuffle{x,x}(keras_learning_phase), was not provided and
  not given a value.Use the Theano flag exception_verbosity='high',for
  more information on this error.", keras_learning_phase)</p>
</blockquote>

<p>I think it makes sense since I have dropout layers in model so it should know current learning phase. How can I set learning phase to 'train'? Or may be different problem here?</p>

<p>Thanks in advance! </p>

<p>Let me answer to this question by myself.</p>

<p>This issue is related only to keras 1.0.0 version and it was fixed in 1.0.2. So code snippet above is perfectly work on newer version of keras, no need to explicitly set learning phase. </p>

<p>More details in <a href="https://github.com/fchollet/keras/issues/2281" rel="nofollow">github issue tread</a>.</p>

python theano keras