[英]Change number of input channels to pretrained keras.applications model?
我正在制作一個深度學習分割模型的原型,它需要六個輸入通道(在不同光照條件下兩個對齊的 448x448 RGB 圖像)。 我希望將幾個預訓練模型的性能與我從頭開始訓練的當前模型的性能進行比較。 我可以將 tf.keras.applications 中的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.
有沒有更好的方法可以在 keras 中使用不同數量的輸入通道的數據上使用預訓練模型? 當輸入通道的數量不同時,預訓練甚至會有所幫助嗎?
從技術上講,它應該是可能的。 也許使用模型的__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()
不過,在概念層面上,我擔心新輸入看起來不像訓練預訓練模型的原始輸入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.