簡體   English   中英

如何將ResNet50隱藏層與另一個模型輸入連接?

[英]How to concatenate ResNet50 hidden layer with another model input?

我試圖將ResNet中隱藏層的輸出與另一個模型的輸入連接起來,但是出現以下錯誤:

ValueError:模型的輸出張量必須是Keras Layer的輸出(因此保留了過去的層元數據)

我正在按照如何在keras中連接兩層中的建議使用Keras的Concatenate層 ,但是它不起作用。 我可能會缺少什么? 我也必須在上面添加一個密集層嗎? 這個想法是直到第二個輸入與第一個輸入連接起來才改變它(合並的輸入將是第三個模型的輸入)。

resnet_features = resnet.get_layer('avg_pool').output
model2_features = Input(shape=(None, 32))
all_features = Concatenate([resnet_features, model2_features])

mixer = Model(inputs=[resnet.input, model2_features], 
                             outputs=all_features)

看起來您在串聯層缺少兩個括號。 它看起來應該像這樣:

all_features = Concatenate()([resnet_features, model2_features])

此外,您必須確保resnet_featuresmodel2_features的形狀相同(除了串聯軸),否則,將無法對其進行串聯。

暫無
暫無

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

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