3 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
我運(yùn)行模型,錯(cuò)誤是: ValueError: Input 0 is incompatible with layer block4_conv1: expected axis -1 of input shape to have value 256 but got shape (None, 250, 250, 32)
刪除輸入形狀keras.layers.Conv2D
并將其添加到 basemodel:
basemodel = VGG19(include_top = False,input_shape=(256,256,3),weights='None')
或者如果你想使用 Imagenet:
basemodel = VGG19(include_top = False,input_shape=(256,256,3),weights='imagenet')
擬合模型并讓我知道發(fā)生的任何錯(cuò)誤。

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
你只從 VGG 模型中提取了一層并以錯(cuò)誤的方式連接它們。這是一種正確的方法:
basemodel = VGG19(include_top = False)
model = tf.keras.Sequential(basemodel.layers[:10])
model.add(keras.layers.Conv2D(32, (7, 7), activation = 'relu'))
model.summary()
請注意,第一層VGG是 anInputLayer所以你應(yīng)該使用basemodel.layers[:11].
請注意,要微調(diào)您的模型,最好修復(fù) VGG 層的權(quán)重:
for layer in model.layers[:10]:
layer.trainable = False

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊
問題是您沒有添加前 10 層,而是從頂部添加了第 10 層。此外,該層的輸入應(yīng)該具有 256 的倍數(shù)的通道。只需將代碼替換為:
model.add(keras.layers.Conv2D(256,(7,7),input_shape = (256,256,3),activation = 'relu'))
添加回答
舉報(bào)