我正在運行圖像分類模型,我的問題是我的驗證準確度高於我的訓練準確率。 數據(火車/驗證)隨機設置。我正在使用InceptionV3作爲預先訓練好的模型。準確度和驗證準確度之間的比率保持相同超過100個時期。
我嘗試了較低的學習率和一個額外的批量標準化層。Keras圖像分類驗證精度更高
有沒有人有什麼想法看什麼?我會感謝一些幫助,謝謝!
base_model = InceptionV3(weights='imagenet', include_top=False)
# add a global spatial average pooling layer
x = base_model.output
x = GlobalAveragePooling2D()(x)
# add a fully-connected layer
x = Dense(468, activation='relu')(x)
x = Dropout(0.5)(x)
# and a logistic layer
predictions = Dense(468, activation='softmax')(x)
# this is the model we will train
model = Model(base_model.input,predictions)
# first: train only the top layers (which were randomly initialized)
# i.e. freeze all convolutional InceptionV3 layers
for layer in base_model.layers:
layer.trainable = False
# compile the model (should be done *after* setting layers to non-trainable)
adam = Adam(lr=0.0001, beta_1=0.9)
model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=['accuracy'])
# train the model on the new data for a few epochs
batch_size = 64
epochs = 100
img_height = 224
img_width = 224
train_samples = 127647
val_samples = 27865
train_datagen = ImageDataGenerator(
rescale=1./255,
#shear_range=0.2,
zoom_range=0.2,
zca_whitening=True,
#rotation_range=0.5,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
'AD/AutoDetect/',
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='categorical')
validation_generator = test_datagen.flow_from_directory(
'AD/validation/',
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='categorical')
# fine-tune the model
model.fit_generator(
train_generator,
samples_per_epoch=train_samples // batch_size,
nb_epoch=epochs,
validation_data=validation_generator,
nb_val_samples=val_samples // batch_size)
找到127647屬於468個類的圖像。
找到27865個屬於468個類的圖像。
Epoch 1/100
2048/1994 [==============================] - 48s - 損失:6.2839 - acc:0.0073 - val_loss:5.8506 - val_acc:0.0179
Epoch 2/100
2048/1994 [=========================== ===] - 44s - 損失:5.8338 - acc:0.0430 - val_loss:5.4865 - val_acc:0.1004
Epoch 3/100
2048/1994 [================ ==============] - 45s - 損失:5.5147 - acc:0.0786 - val_loss:5.1474 - val_acc:0.1161
Epoch 4/100
2048/1994 [===== =========================] - 44s - 損失:5.1921 - acc:0.1074 - val_loss:4.8049 - val_acc:0.1786
你能提供更多的細節,爲什麼你縮放,翻轉和美白你的數據?擁有超過10萬張圖片,您似乎有足夠的數據至少可以嘗試不增加。除此之外,你可以給你的完全連接層增加一點複雜性。我會嘗試1024個神經元或更大,並將擺脫Dropout/BatchNorm。 – petezurich
只是爲了完整性:適當的圖像尺寸是299x299px。 224用於VGG。看到這裏:https://keras.io/applications/ – petezurich