title: Replacing the input layer of a pre-trained model with different channels?
body: <p>I want to re-use the pre-trained weights of <code>MobiletNetv2</code>, but with images with <strong>12</strong> channels. I know this needs to create more weights, but that's okay because I want to re-train anyway. I can't find a way to make it work.</p>
  <pre><code>import tensorflow as tf
  
  class CNN(tf.keras.Model):
      def __init__(self):
          super(CNN, self).__init__()
          self.input_layer = tf.keras.layers.InputLayer(input_shape=(None, 224, 224, 12))
          self.base = tf.keras.applications.MobileNetV2(input_shape=(224, 224, 3),
                                                        include_top=False,
                                                        weights='imagenet')
          _ = self.base._layers.pop(0)
          self.flat1 = tf.keras.layers.Flatten()
          self.dens3 = tf.keras.layers.Dense(10)
  
      def call(self, x, **kwargs):
          x = self.input_layer(x)
          x = self.base(x)
          x = self.flat1(x)
          x = self.dens3(x)
          return x
  
  model = CNN()
  model.build(input_shape=(None, 224, 224, 12))
  </code></pre>
  <blockquote>
  <p>ValueError: Input 0 is incompatible with layer mobilenetv2_1.00_224: expected shape=(None, 224, 224, 3), found shape=(None, 224, 224, 12)</p>
  </blockquote>
  <p>I tried popping the first layer like in other answers.</p>