title: Freeze sublayers in tensorflow 2
body: <p>I have a model which is composed of custom layers. Each custom layer contains many tf.keras.layers. The problem is that if I want to freeze those layers after defining my model, the loop:</p>
  
  <pre><code>for i, layer in enumerate(model.layers):
      print(i, layer.name)
  </code></pre>
  
  <p>only prints the "outer" custom layers and not those who exist inside. Is there any way to access the inner layers so I can freeze them?</p>
  
  <p>an example of a custom layer from the <a href="https://www.tensorflow.org/guide/keras/custom_layers_and_models" rel="nofollow noreferrer">official tf docs</a>:</p>
  
  <pre><code>class MLPBlock(layers.Layer):
  
    def __init__(self):
      super(MLPBlock, self).__init__()
      self.linear_1 = Linear(32)
      self.linear_2 = Linear(32)
      self.linear_3 = Linear(1)
  
    def call(self, inputs):
      x = self.linear_1(inputs)
      x = tf.nn.relu(x)
      x = self.linear_2(x)
      x = tf.nn.relu(x)
      return self.linear_3(x)
  </code></pre>