1 回答
TA貢獻1877條經(jīng)驗 獲得超1個贊
keras的功能API更適合這種問題:
model = VGG16(weights='imagenet', include_top=False, input_shape=inputshape)
x = model.output
x = Conv2D(4096, kernel_size=(8, 8), activation="relu")(x)
x = Conv2D(4096, kernel_size=(1, 1), activation="relu")(x)
out = Conv2D(16, kernel_size=(1, 1), activation="softmax")(x)
F2model = Model(inputs=model.inputs, outputs=out)
for layer in F2model.layers[:25]:
layer.trainable = False
此外,我看到您正在使用具有softmax激活的binary_crossentropy,這可能會導(dǎo)致一些問題:
- 使用softmax和categorical_crossentropy
- 使用sigmoid和binary_crossentropy
并且要小心這個模型,使用4096的卷積將使你的參數(shù)數(shù)量真的非常動!
(本例中為 1.65 億)
編輯
看起來你的問題只來自你的標(biāo)簽數(shù)組:
您的最后一層是卷積層,因此它期望一個帶有形狀的4D數(shù)組,但您正在給它一個形狀數(shù)組
(batch_size, height, width, channel)(batch_size, 16)因此,要么將最后一層更改為:
out = Dense(16, activation="softmax")(x)
或者將標(biāo)簽數(shù)組更改為卷積層可接受。
添加回答
舉報
