title: How can I use the output of intermediate layer of one model as input to another model?
body: <p>I train a model <code>A</code> and try to use the output of the intermediate layer with the <code>name="layer_x"</code> as an additional input for model <code>B</code>.</p>
  
  <p>I tried to use the output of the intermediate layer like on the Keras doc 
  <a href="https://keras.io/getting-started/faq/#how-can-i-obtain-the-output-of-an-intermediate-layer" rel="nofollow noreferrer">https://keras.io/getting-started/faq/#how-can-i-obtain-the-output-of-an-intermediate-layer</a>.</p>
  
  <p>Model A:</p>
  
  <pre><code>inputs = Input(shape=(100,))
  dnn = Dense(1024, activation='relu')(inputs)
  dnn = Dense(128, activation='relu', name="layer_x")(dnn)
  dnn = Dense(1024, activation='relu')(dnn)
  output = Dense(10, activation='softmax')(dnn)
  </code></pre>
  
  <p>Model B:</p>
  
  <pre><code>input_1 = Input(shape=(200,))
  input_2 = Input(shape=(100,)) # input for model A
  
  # loading model A
  model_a = keras.models.load_model(path_to_saved_model_a)
  
  intermediate_layer_model = Model(inputs=model_a.input, 
                                   outputs=model_a.get_layer("layer_x").output)
  
  intermediate_output = intermediate_layer_model.predict(data)
  
  merge_layer = concatenate([input_1, intermediate_output])
  dnn_layer = Dense(512, activation="relu")(merge_layer)
  output = Dense(5, activation="sigmoid")(dnn_layer)
  model = keras.models.Model(inputs=[input_1, input_2], outputs=output)
  </code></pre>
  
  <p>When I debug I get an error on this line:</p>
  
  <pre><code>intermediate_layer_model = Model(inputs=model_a.input, 
                                   outputs=model_a.get_layer("layer_x").output)
  
  File "..", line 89, in set_model
    outputs=self.neural_net_asc.model.get_layer("layer_x").output)
  File "C:\WinPython\python-3.5.3.amd64\lib\site-packages\keras\legacy\interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "C:\WinPython\python-3.5.3.amd64\lib\site-packages\keras\engine\topology.py", line 1592, in __init__
    mask = node.output_masks[tensor_index]
  AttributeError: 'Node' object has no attribute 'output_masks'
  </code></pre>
  
  <p>I can access the tensor with <code>get_layer("layer_x").output</code> and the <code>output_mask</code> is <code>None</code>. Do I have to set manually an output mask and how do I set up this output mask if needed?</p>