![](/img/trans.png)
[英]ResNet50 Model is not learning with transfer learning in keras
[英]How to fo transfer learning of a resnet50 model with with own dataset?
我正在嘗試使用具有 vggface 權重的 keras 和 resnet50 模型構建人臉驗證系統。 我試圖實現這一目標的方法是通過以下步驟:
使用 resnet50 的預訓練模型,我得到了相當不錯的結果。 但是由於該模型主要是根據歐洲數據進行訓練的,而且我想要對印度子大陸進行人臉驗證,因此我不能依賴它。 我想在我自己的數據集上訓練它們。 我有 10000 個類,每個類包含 2 個圖像。 通過圖像增強,我可以從這兩個圖像中為每個類創建 10-15 個圖像。
這是我用於訓練的示例代碼
base_model = VGGFace(model='resnet50',include_top=False,input_shape=(224, 224, 3))
base_model.layers.pop()
base_model.summary()
for layer in base_model.layers:
layer.trainable = False
y=base_model.input
x=base_model.output
x=GlobalAveragePooling2D()(x)
x=Dense(1024,activation='relu')(x) #we add dense layers so that the model can learn more complex functions and classify for better results.
x=Dense(1024,activation='relu')(x) #dense layer 2
x=Dense(512,activation='relu')(x) #dense layer 3
preds=Dense(8322,activation='softmax')(x) #final layer with softmax activation
model=Model(inputs=base_model.input,outputs=preds)
model.compile(optimizer='Adam',loss='categorical_crossentropy',metrics=['accuracy'])
model.summary()
train_datagen=ImageDataGenerator(preprocessing_function=preprocess_input) #included in our dependencies
train_generator=train_datagen.flow_from_directory('/Users/imac/Desktop/Fayed/Facematching/testenv/facenet/Dataset/train', # this is where you specify the path to the main data folder
target_size=(224,224),
color_mode='rgb',
batch_size=32,
class_mode='categorical',
shuffle=True)
step_size_train=train_generator.n/train_generator.batch_size
model.fit_generator(generator=train_generator,
steps_per_epoch=step_size_train,
epochs=10)
model.save('directory')
就代碼代碼而言,我所理解的是我禁用最后一層,然后添加 4 層訓練它們並將它們存儲在目錄中。
然后我使用加載模型
model=load_model('directory of my saved model')
model.summary()
yhat = model.predict(samples)
我預測兩個圖像的嵌入,然后計算余弦距離。 但問題是我的訓練模型的預測變得更糟。 對於同一個人的兩張圖像,預訓練模型給出的距離為 0.3,而我的訓練模型顯示距離為 1.0。 雖然在訓練過程中損失函數隨着每個時期的推移而減少並且准確度在增加,但這並沒有反映在我的預測輸出上。 我想增加預訓練模型的預測結果。
我怎樣才能用我自己的數據實現這一目標?
注意:我在機器學習方面相對較新,對模型層了解不多
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.