title: How to prevent backpropagation after compiling a keras model?
body: <p>I have a multi output model such as this</p>
  <pre><code>       input
           |
        hidden
           |
          / \
         /   \
  output1    output2
  </code></pre>
  <p>I can train this model by <code>model.train_on_batch(input=input,output=[output1,output2])</code> but at some particulat stage in my training I want to train only one branch (output2) of this model and prevent backpropogation from output1. I initally tried passing a <code>None</code> value in the model <code>model.train_on_batch(input=input,output=[None,output2])</code>  but its showing</p>
  <blockquote>
  <p>AttributeError: 'NoneType' object has no attribute 'shape'</p>
  </blockquote>
  <p>Then I tried passing a NaN arrays of output1 shape <code>model.train_on_batch(input=input,output=[Nan_array,output2])</code> then the loss becomes <code>NaN</code>. How can I train only one branch in a multi output keras model and prevent backpropogation in the other?</p>
  <h1>Edit</h1>
  <p>I was trying to find a solution to this problem and came across <code>K.stop_gradient</code> function. I tried to stop backpropogaion in a one output model like this</p>
  <pre><code>import numpy as np
  from keras.models import Sequential
  from keras.layers import Dense, Dropout
  import keras.backend as K
  
  def loss(y_true, y_pred):
      return K.stop_gradient(y_pred)
      
  # Generate dummy data
  x_train = np.random.random((10, 20))
  y_train = np.random.randint(2, size=(10, 1))
  x_test = np.random.random((10, 20))
  y_test = np.random.randint(2, size=(10, 1))
  
  model = Sequential()
  model.add(Dense(64, input_dim=20, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(64, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(1, activation='sigmoid'))
  
  model.compile(loss=loss,
                optimizer='rmsprop',
                metrics=['accuracy'])
  
  model.fit(x_train, y_train,
            epochs=1,
            batch_size=128)
  
  score = model.evaluate(x_test, y_test, batch_size=128)
  </code></pre>
  <p>But gets this error</p>
  <blockquote>
  <p>ValueError: Tried to convert 'x' to a tensor and failed. Error: None values not supported.</p>
  </blockquote>