Skip to content
Advertisement

I would try change channel for keras pretrained model

I got an Xception model.

Xception = tf.keras.applications.Xception(input_shape=(512, 512, 3), include_top=False)

I have combined the model to change the Input Channel to 3.

input_layer = keras.Input(shape=(512, 512, 1), name="img_input")
x = layers.UpSampling3D(size=(1, 1, 3), name="output")(input_layer)
input_model = keras.Model(input_layer, x, name="input_model")

model = keras.Model(input_model, Xception, name="model")

however I have got error

Input tensors to a Functional must come from `tf.keras.Input`. Received: <tensorflow.python.keras.engine.functional.Functional object at 0x7f922942a690> (missing previous layer metadata).

Advertisement

Answer

You simply have to embed Xception in the correct way in your new model:

Xception = tf.keras.applications.Xception(input_shape=(512, 512, 3), include_top=False)

input_layer = tf.keras.Input(shape=(512, 512, 1), name="img_input")
x = tf.keras.layers.UpSampling3D(size=(1, 1, 3), name="upsampling")(input_layer)
output = Xception(x)

model = tf.keras.Model(input_layer, output, name="model")

We create a new Input layer, than we operate upsampling and in the end we pass all to Xception

Here is the running notebook if you are interested

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement