title: Does the way I create and store layers in subclassed Keras `Model` have any effect?
body: <p>AKA Keras <code>Model</code> subclassing magic.</p>
  
  <p>While playing with Keras, I noticed, that <code>ResNetBlock.layers</code> gets populated as I put new instances of layers into collections I previously put into my custom model.</p>
  
  <pre class="lang-py prettyprint-override"><code>class ResNetBlock(Model):
      PART_COUNT = 3
  
      def __init__(self, kernel_size, filters):
          super().__init__()
          self.convs = []
          self.batchNorms = []
  
          for part in range(ResNetBlock.PART_COUNT):
              if part == 1:
                  conv = Conv2D(filters[part], kernel_size=kernel_size, padding="same")
              else:
                  conv = Conv2D(filters[part], kernel_size=(1,1))
              self.convs.append(conv)
              self.batchNorms.append(BatchNormalization())
  
  resnet = ResNetBlock(1, [1, 2, 3])
  print(resnet.layers) # actually prints non-empty list
                       # filled with Conv2Ds and BNs from above
  </code></pre>
  
  <p>Adopted from official tutorial: <a href="https://www.tensorflow.org/beta/tutorials/eager/custom_layers" rel="nofollow noreferrer">https://www.tensorflow.org/beta/tutorials/eager/custom_layers</a></p>
  
  <p>A bit of digging into TensorFlow source showed, that some kind of tracking is used via <code>__setattr__</code> in <code>Network</code> class.</p>
  
  <p>Now the code is not trivial, documentation lacking, and it seems unclear if the order of creating new layers/adding them to respective collections matters at all? E.g. if I first fill in <code>convs</code> collection, and only then <code>batchNorms</code> collection, would it still be the same model?</p>
  
  <p>In most tutorials each layer is actually put into its own attribute.</p>
  
  <p>Bonus question is: why is it done so implicitly? This kind of magic kinda breaks the motto to prefer explicit over implicit. What if for some reason I'd need to use a custom collection type not derived from <code>list</code>? How would I ensure these magic operations are done properly?</p>