我得到了一个Xception模型。
Xception = tf.keras.applications.Xception(input_shape=(512, 512, 3), include_top=False)
我已经组合了模型以将输入通道更改为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")
然而,我遇到了错误
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).
回答:
你只需要以正确的方式将Xception
嵌入到你的新模型中:
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")
我们创建一个新的Input
层,然后进行上采样,最后将所有内容传递给Xception
这里是有运行笔记本,如果你感兴趣的话