数据增强损害准确性Keras [英] Data Augmentation hurts accuracy Keras

查看:205
本文介绍了数据增强损害准确性Keras的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python进行深度学习 第5.3节使用数据增强功能提取特征" 来解决带有resnet50(图像网络权重)的3类问题.

I'm trying to adapt Deep Learning with Python section 5.3 Feature extraction with Data Augmentation to a 3-class problem with resnet50 (imagenet weights).

完整代码位于 https://github.com/morenoh149/plantdisease

from keras import models
from keras import layers
from keras.applications.resnet50 import ResNet50
from keras import optimizers
from keras.preprocessing.image import ImageDataGenerator

input_shape = (224, 224, 3)
target_size = (224, 224)
batch_size = 20

conv_base = ResNet50(weights='imagenet', input_shape=input_shape, include_top=False)

model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dense(256, activation='relu'))
model.add(layers.Dense(3, activation='softmax'))

conv_base.trainable = False

train_datagen = ImageDataGenerator(rescale=1./255)
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
    'input/train',
    target_size=target_size,
    batch_size=batch_size,
    class_mode='categorical')
validation_generator = test_datagen.flow_from_directory(
    'input/validation',
    target_size=target_size,
    batch_size=batch_size,
    class_mode='categorical')
model.compile(loss='categorical_crossentropy',
             optimizer=optimizers.RMSprop(lr=2e-5),
             metrics=['acc'])
history = model.fit_generator(
    train_generator,
    steps_per_epoch=96,
    epochs=30,
    verbose=2,
    validation_data=validation_generator,
    validation_steps=48)

问题:

  • 这本书对ImageDataGenerator和选择steps_per_epochvalidation_steps没多大帮助.这些值应该是什么? 我有3个班级,每个班级有1000张图片.我将其拆分为60/20/20训练/验证/测试.
  • 在不增加数据的情况下,我能够获得60%的验证精度.上面我已经简化了ImageDataGenerator以仅重新缩放.该模型的验证精度为何为30%?
  • 我需要对该脚本的数据增强版本进行哪些更改,以使其准确性与不进行扩充相符?
  • the book doesn't go much into ImageDataGenerator and selecting steps_per_epoch and validation_steps. What should these values be? I have 3 classes, 1000 images each. I've split it 60/20/20 train/validation/test.
  • I was able to get a validation accuracy of 60% without data augmentation. Above I've simplified the ImageDataGenerator to only rescale. This model has a validation accuracy of 30% Why?
  • What changes do I need to make to the data-augmented version of this script to match the accuracy with no augmentation?

更新: 这可能是keras本身的问题

UPDATE: This may be an issue with keras itself

  • https://github.com/keras-team/keras/issues/9214
  • https://github.com/keras-team/keras/pull/9965

推荐答案

要回答您的第一个问题:steps_per_epoch是训练生成器在考虑一个纪元完成之前应该产生的批处理数量.如果您有600个批量为20的训练图像,则每个时期等30个步骤. validation_steps将相同的逻辑应用于验证数据生成器,无论是在每个纪元的结尾.

To answer your first question: steps_per_epochis the number of batches the training generator should yield before considering an epoch finished. If you have 600 training images with batch size 20, this would be 30 steps per epoch et cetera. validation_steps applies the same logic to the validation data generator, be it at the end of each epoch.

通常,steps_per_epoch是数据集的大小除以批处理大小.

In general, steps_per_epoch is the size of your dataset divided by the batch size.

这篇关于数据增强损害准确性Keras的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆