title: Implementation of Adversarial Loss In Keras
body: <p>I'm trying to implement an adversarial loss in keras. 
  The model consists of two networks, one auto-encoder (the target model) and one discriminator. The two models share the encoder. </p>
  
  <p>I created the adversarial loss of the auto-encoder by setting a keras variable</p>
  
  <pre><code>def get_adv_loss(d_loss):
      def loss(y_true, y_pred):
          return some_loss(y_true, y_pred) - d_loss
      return loss
  
  discriminator_loss = K.variable()
  L = get_adv_loss(discriminator_loss)
  autoencoder.compile(..., loss=L)
  </code></pre>
  
  <p>and during training I interleave <code>train_on_batch</code> of <code>discriminator</code> and <code>autoencoder</code> to update <code>discriminator_loss</code> </p>
  
  <pre><code>d_loss = disciminator.train_on_batch(x, y_domain)
  discriminator_loss.assign(d_loss)
  a_loss, ... = self.segmenter.train_on_batch(x, y_target)
  </code></pre>
  
  <p>However, I found out that the value of these variables is frozen when the model is compiled. I tried to recompile the model during training but that raise the error </p>
  
  <blockquote>
    <p>Node 'IsVariableInitialized_13644': Unknown input node
    'training_12/Adam/Variable'</p>
  </blockquote>
  
  <p>which I guess it means i cant recompile during training? any suggestion on how i can inject the discriminator loss in the autoencoder?</p>