【问题标题】:Keras image classification validation accuracy higherKeras图像分类验证准确率更高
【发布时间】:2017-11-20 09:48:38
【问题描述】:

我正在运行一个包含图像的图像分类模型,我的问题是我的验证准确度高于我的训练准确度。 数据(训练/验证)是随机设置的。我使用 InceptionV3 作为预训练模型。准确率和验证准确率之间的比率在 100 个 epoch 内保持不变。
我尝试了较低的学习率和额外的批量标准化层。

有人对要研究的内容有任何想法吗?非常感谢您的帮助,谢谢!

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)

找到属于 468 个类别的 127647 张图片。
找到属于 468 个类别的 27865 张图片。
纪元 1/100
2048/1994 [===============================] - 48s - 损失:6.2839 - acc:0.0073 - val_loss:5.8506 - val_acc:0.0179
纪元 2/100
2048/1994 [===============================] - 44s - 损失:5.8338 - acc:0.0430 - val_loss:5.4865 - val_acc:0.1004
纪元 3/100
2048/1994 [===============================] - 45s - 损失:5.5147 - acc:0.0786 - val_loss:5.1474 - val_acc:0.1161
纪元 4/100
2048/1994 [===============================] - 44s - 损失:5.1921 - acc:0.1074 - val_loss:4.8049 - val_acc: 0.1786

【问题讨论】:

  • 您能否详细说明为什么要缩放、翻转和白化数据?拥有超过 10 万张图像,您似乎有足够的数据至少可以尝试不进行增强。除此之外,您还可以给全连接层增加一点复杂性。我会尝试 1024 个或更大的神经元,并摆脱 Dropout / BatchNorm。
  • 仅出于完整性考虑:Inception 的正确图像尺寸为 299x299px。 224 用于 VGG。见这里:keras.io/applications

标签: python image deep-learning classification keras


【解决方案1】:

see this answer

这是因为您在模型中添加了一个 dropout 层,以防止在训练期间准确度达到 1.0。

【讨论】:

    猜你喜欢
    • 2019-02-14
    • 2018-09-18
    • 2020-02-12
    • 2019-08-20
    • 2018-07-20
    • 2020-04-23
    • 2020-08-13
    • 1970-01-01
    • 2020-02-02
    相关资源
    最近更新 更多