I want to re-use the pre-trained weights of MobiletNetv2, but with images with 12 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.
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))
ValueError: Input 0 is incompatible with layer mobilenetv2_1.00_224: expected shape=(None, 224, 224, 3), found shape=(None, 224, 224, 12)
I tried popping the first layer like in other answers.