将输入通道的数量更改为预训练的 keras.applications 模型?

Mas*_*ugh 3 python deep-learning keras tensorflow

我正在制作一个深度学习分割模型的原型,它需要六个输入通道(在不同光照条件下两个对齐的 448x448 RGB 图像)。我希望将几个预训练模型的性能与我从头开始训练的当前模型的性能进行比较。我可以将预训练模型tf.keras.applications用于超过 3 个通道的输入图像吗?

我尝试先应用卷积将通道维度减少到 3,然后将该输出传递给tf.keras.applications.DenseNet121()但收到以下错误:

import tensorflow as tf
dense_input = tf.keras.layers.Input(shape=(448, 448, 6))
dense_filter = tf.keras.layers.Conv2D(3, 3, padding='same')(dense_input)
dense_stem = tf.keras.applications.DenseNet121(include_top=False, weights='imagenet', input_tensor=dense_filter)
*** ValueError: You are trying to load a weight file containing 241 layers into a model with 242 layers.
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法可以在 keras 中使用不同数量的输入通道的数据上使用预训练模型?当输入通道的数量不同时,预训练甚至会有所帮助吗?

Kri*_*ris 6

从技术上讲,它应该是可能的。也许使用模型__call__本身:

orig_model = tf.keras.applications.DenseNet121(include_top=False, weights='imagenet')
dense_input = tf.keras.layers.Input(shape=(448, 448, 6))
dense_filter = tf.keras.layers.Conv2D(3, 3, padding='same')(dense_input)
output = orig_model(dense_filter)

model = tf.keras.Model(dense_input, output)
model.compile(...)
model.summary()
Run Code Online (Sandbox Code Playgroud)

不过,在概念层面上,我担心新输入看起来不像训练预训练模型的原始输入。