【发布时间】:2017-07-21 14:34:06
【问题描述】:
我有以下代码使用列表中的数据作为输入进行数据扩充:
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img import PIL
def augment(file_images_path, dir_save):
datagen = ImageDataGenerator(rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest')
with open(file_images_path) as f:
images_names = f.readlines()
images_names = [x.strip() for x in images_names]
for line in images_names:
img=PIL.Image.open(line)
img=img.resize((28,28))
x = img_to_array(img)
x = x.reshape((1,) + x.shape)
# the .flow() command below generates batches of randomly transformed
#images and saves the results to the `dir_save` directory
i = 0
for batch in datagen.flow(x, batch_size=1, save_to_dir=dir_save, save_prefix='augmented', save_format='tif'):
i += 1
if i > 2:
break # otherwise the generator would loop indefinitely
我是 Keras 数据增强方面的新手,我想知道 Keras 每次迭代对我的图像执行多少图像操作。例如,如果我在包含 14 个图像的列表上运行此代码,它将生成 126 个增强图像。如果我在包含 125 个图像的列表上运行它,它将生成 370 个增强图像。我的问题是:为什么?
【问题讨论】:
标签: python tensorflow keras