我有一个 Xception 模型。
Xception = tf.keras.applications.Xception(input_shape=(512, 512, 3), include_top=False)
我已组合模型,将输入 channel 更改为 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
Here如果您有兴趣,就是正在运行的笔记本
关于python - 我会尝试更改 keras 预训练模型的 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68785255/