我想微調Keras中的預先訓練的Inceptionv3中的多標籤(17)預測問題。微調Keras中的Inception_v3時的ValueError
下面的代碼:
# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)
# add a new top layer
x = base_model.output
predictions = Dense(17, activation='sigmoid')(x)
# this is the model we will train
model = Model(inputs=base_model.input, outputs=predictions)
# we need to recompile the model for these modifications to take effect
# we use SGD with a low learning rate
from keras.optimizers import SGD
model.compile(loss='binary_crossentropy', # We NEED binary here, since categorical_crossentropy l1 norms the output before calculating loss.
optimizer=SGD(lr=0.0001, momentum=0.9))
# Fit the model (Add history so that the history may be saved)
history = model.fit(x_train, y_train,
batch_size=128,
epochs=1,
verbose=1,
callbacks=callbacks_list,
validation_data=(x_valid, y_valid))
但我鑽進了以下錯誤消息,並且有麻煩破譯它是說:
ValueError: Error when checking target: expected dense_1 to have 4 dimensions, but got array with shape (1024, 17)
這似乎有事情做與它不不喜歡我爲標籤作爲目標的熱門編碼。但是,我如何獲得4個維度的目標?
看來,https://stackoverflow.com/questions/41764041/fine-tuning-pretrained-model-in-keras可能有答案? –
或者https://stackoverflow.com/questions/43386463/keras-vgg16-fine-tuning?rq=1 –