From cbc6eac094aea323a33993f1fcd088fe3a16164c Mon Sep 17 00:00:00 2001 From: ivdorelian Date: Fri, 22 Apr 2016 22:55:20 +0300 Subject: [PATCH] Fixed error when trying to use models with Dropout or Weight Regularizers As per https://github.com/fchollet/keras/issues/2417 the train mode is explicitly passed to K.function in order to avoid errors. --- qlearning4k/memory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qlearning4k/memory.py b/qlearning4k/memory.py index 82bcd9e..634067a 100644 --- a/qlearning4k/memory.py +++ b/qlearning4k/memory.py @@ -92,7 +92,7 @@ def set_batch_function(self, model, input_shape, batch_size, nb_actions, gamma): Qsa = K.reshape(Qsa, (batch_size, nb_actions)) delta = K.reshape(self.one_hot(a, nb_actions), (batch_size, nb_actions)) targets = (1 - delta) * Y[:batch_size] + delta * (r + gamma * (1 - game_over) * Qsa) - self.batch_function = K.function(inputs=[samples], outputs=[S, targets]) + self.batch_function = K.function(inputs=[samples, K.learning_phase()], outputs=[S, targets]) def one_hot(self, seq, num_classes): import theano.tensor as T @@ -104,5 +104,5 @@ def get_batch_fast(self, model, batch_size, gamma): samples = np.array(sample(self.memory, batch_size)) if not hasattr(self, 'batch_function'): self.set_batch_function(model, self.input_shape, batch_size, model.output_shape[-1], gamma) - S, targets = self.batch_function([samples]) + S, targets = self.batch_function([samples, 1]) return S, targets