title: In Keras, how to get the layer name associated with a "Model" object contained in my model?
body: <p>I built a Sequential model with the VGG16 network at the initial base, for example: </p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>from keras.applications import VGG16
  conv_base = VGG16(weights='imagenet',
                    # do not include the top, fully-connected Dense layers 
                    include_top=False,
                    input_shape=(150, 150, 3))
  
  from keras import models
  from keras import layers
  
  model = models.Sequential()
  model.add(conv_base)
  model.add(layers.Flatten())
  model.add(layers.Dense(256, activation='relu'))
  # the 3 corresponds to the three output classes
  model.add(layers.Dense(3, activation='sigmoid'))
  </code></pre>
  
  <p>My model looks like this: </p>
  
  <pre class="lang-python prettyprint-override"><code>model.summary()
  </code></pre>
  
  <blockquote>
    <hr>
  
  <pre class="lang-python prettyprint-override"><code>Layer (type)                 Output Shape              Param #   
  =================================================================
  vgg16 (Model)                (None, 4, 4, 512)         14714688  
  _________________________________________________________________
  flatten_1 (Flatten)          (None, 8192)              0         
  _________________________________________________________________
  dense_7 (Dense)              (None, 256)               2097408   
  _________________________________________________________________
  dense_8 (Dense)              (None, 3)                 771       
  =================================================================
  Total params: 16,812,867
  Trainable params: 16,812,867
  Non-trainable params: 0
  _________________________________________________________________
  </code></pre>
  </blockquote>
  
  <p>Now, I want to get the layer names associated with the vgg16 Model portion of my network.  I.e. something like: </p>
  
  <pre class="lang-python prettyprint-override"><code>layer_name = 'block3_conv1'
  filter_index = 0
  
  layer_output = model.get_layer(layer_name).output
  loss = K.mean(layer_output[:, :, :, filter_index])
  </code></pre>
  
  <p>However, since the vgg16 convolutional is shown as a Model and it's layers are not being exposed, I get the error: </p>
  
  <blockquote>
    <p>ValueError: No such layer: block3_conv1</p>
  </blockquote>
  
  <p>How do I do this? </p>