title: Reusing a group of Keras layers
body: <p>I know that you can reuse Keras layers. For eg I declare two layers for a decoder network:</p>
  
  <pre><code>decoder_layer_1 = Dense(intermediate_dim,activation='relu',name='decoder_layer_1')
  decoder_layer_2 = Dense(intermediate_dim,activation='relu',name='decoder_layer_2')
  </code></pre>
  
  <p>Use in first model:</p>
  
  <pre><code>decoded = decoder_layer_1(z)
  decoded = decoder_layer_2(decoded)
  </code></pre>
  
  <p>Use in second model:</p>
  
  <pre><code>_decoded = decoder_layer_1(decoder_input)
  _decoded = decoder_layer_2(_decoded)
  </code></pre>
  
  <p>The above method is ok if I need to reuse only a couple of layers, cumbersome if I want to reuse a large number of layers (for eg. a decoder network with 10 layers). Is there a more efficient means to do it other than explicitly declaring each layer. Is there a means to implement it as shown below:</p>
  
  <pre><code>decoder_layers = group_of_layers() 
  </code></pre>
  
  <p>Reuse in the first model:</p>
  
  <pre><code>decoded = group_of_layers(z)
  </code></pre>
  
  <p>Reuse in the second model:</p>
  
  <pre><code>_decoded = group_of_layers(decoder_input)
  </code></pre>