Keras:使用flow_from_directory绘制图像增强样本以训练数据

时间:2020-06-10 06:16:05

标签: python keras computer-vision data-augmentation

我正在使用Keras flow_from_directory执行数据扩充:

from keras.applications.inception_v3 import preprocess_input
from keras.preprocessing.image import ImageDataGenerator

batch_size = 32

# Create train generator
train_datagen = ImageDataGenerator(preprocessing_function=preprocess_input, 
                                  rotation_range = 15,
                                  width_shift_range = 0.2,
                                  height_shift_range = 0.2,
                                  shear_range = 10,
                                  brightness_range = (0.8,0.9)) 

train_generator = train_datagen.flow_from_directory(directory = '../input/train/',
                                                    target_size=(299,299),
                                                    color_mode='rgb',
                                                    batch_size=batch_size,
                                                    class_mode='binary', # if not binary, set to categorical
                                                    shuffle = True, seed = 0)

如何绘制示例图像及其数据增强示例?

例如,我的目录是../input/train/cats/../input/train/dogs/

1 个答案:

答案 0 :(得分:0)

生成器只会在增强后为您提供img,并非没有

如果您想查看图像之间的差异,我会:

  1. 按照字母数字顺序排列名称,以便00001.jpg,00002.jpg .....
  2. 使用shuffle = False,batch_size = 1

因此,生成器将按给定顺序生成img。然后,生成器将为您提供的第一个img是00001.jpg的提示,第二个是00002.jpg的提示,依此类推。