在Inception ResnetV2上进行Keras转移学习-由于'val_acc'并没有改善,因此培训在两者之间停止

时间:2018-08-11 10:34:00

标签: python tensorflow keras deep-learning resnet

我正在尝试使用Inception ResnetV2KERAS模型上测试一些名人图像以进行面部识别

现在,我尝试使用epochs = 50进行培训,但是由于Epoch 00027并没有改善,培训在validation_accuracy处停止了。

enter image description here

现在我知道这是数据过度拟合的情况。我不确定要调整哪些参数以及要进行哪些更改以避免过度拟合。我可能做错了事。

这是一些重要的代码部分,可用于识别问题

模型:

model = applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights='imagenet', input_shape = (img_width, img_height, 3))

制作前5层trainable = false

for layer in model.layers[:5]:
    layer.trainable = False

添加自定义图层:

x = model.output
x = Flatten()(x)
x = Dense(1024, activation="relu")(x)
x = Dropout(0.5)(x)
x = Dense(1024, activation="relu")(x)
predictions = Dense(10, activation="softmax")(x)

模型编译和其他超参数:

model_final.compile(loss = "categorical_crossentropy", optimizer = optimizers.SGD(lr=0.0001, momentum=0.9), metrics=["accuracy"])

数据增强:

train_datagen = ImageDataGenerator(
    rescale = 1./255,
    horizontal_flip = True,
    fill_mode = "nearest",
    zoom_range = 0.3,
    width_shift_range = 0.3,
    height_shift_range=0.3,
    rotation_range=30)

test_datagen = ImageDataGenerator(
    rescale = 1./255,
    horizontal_flip = True,
    fill_mode = "nearest",
    zoom_range = 0.3,
    width_shift_range = 0.3,
    height_shift_range=0.3,
    rotation_range=30)

检查点和早期停止:

checkpoint = ModelCheckpoint("custom_resnet.h5", monitor='val_acc', verbose=1, save_best_only=True, save_weights_only=False, mode='auto', period=1)
early = EarlyStopping(monitor='val_acc', min_delta=0, patience=10, verbose=1, mode='auto')

我想弄清楚为什么验证精度会这么低。
任何帮助都会很棒 谢谢:)

0 个答案:

没有答案
相关问题