title: Extracting last layers of keras model as a submodel
body: <p>Say we have a convolutional neural network M. I can extract features from  images by using </p>
  
  
  
  <pre><code>extractor = Model(M.inputs, M.get_layer('last_conv').output)
  features = extractor.predict(X)
  </code></pre>
  
  <p>How can I get the model that will predict classes using <code>features</code>?</p>
  
  <p>I can't use the following lines because it requires the input of the model to be a placeholder.</p>
  
  
  
  <pre><code>predictor = Model([M.get_layer('next_layer').input], M.outputs)
  pred = predictor.predict(features)
  </code></pre>
  
  <p>I also can't use <code>K.function</code> because later I want to use it as part of another model, so I will be appliyng predictor to tf.tensor, not np.array.</p>