簡體   English   中英

將輸入通道的數量更改為預訓練的 keras.applications 模型?

[英]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()

不過,在概念層面上,我擔心新輸入看起來不像訓練預訓練模型的原始輸入。

跨模態預訓練可能是您需要的方法。 王等人提出。 (2016) ,該方法對第一層中各個通道的預訓練模型的權重進行平均,並通過目標通道的數量復制平均值。 實驗結果表明,即使有 20 個輸入通道且其輸入模態不是 RGB,使用這種預訓練方法的網絡也能獲得更好的性能。

要應用這一點,可以參考另一個使用 layer.get_weights() 和 layer.set_weights() 手動設置預訓練模型第一層權重的答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM