在 Keras ImageDataGenerator 流程方法中遇到 save_to_dir 问题
Having trouble with save_to_dir in Keras ImageDataGenerator flow method
我想保存我的 ImageDataGenerator 正在创建的增强图像,以便我以后可以使用它们。当我执行下面的代码时,它运行良好,但是我希望保存的图像没有出现在我试图保存它们的目录中。
gen = image.ImageDataGenerator(rotation_range=17, width_shift_range=0.12,
height_shift_range=0.12, zoom_range=0.12, horizontal_flip=True, dim_ordering='th')
batches = gen.flow_from_directory(path+'train', target_size=(224,224),
class_mode='categorical', shuffle=False, batch_size=batch_size, save_to_dir=path+'augmented', save_prefix='hi')
我觉得我一定没有正确使用这个功能。知道我做错了什么吗?
gen.flow_from_directory
给你一个发电机。图像并不是真正生成的。为了获取图像,您可以遍历生成器。例如
i = 0
for batch in gen.flow_from_directory(path+'train', target_size=(224,224),
class_mode='categorical', shuffle=False, batch_size=batch_size,
save_to_dir=path+'augmented', save_prefix='hi'):
i += 1
if i > 20: # save 20 images
break # otherwise the generator would loop indefinitely
它只是一个声明,你必须使用那个生成器,例如.next()
batches.next()
然后您将在 path+'augmented'
中看到图片
我想保存我的 ImageDataGenerator 正在创建的增强图像,以便我以后可以使用它们。当我执行下面的代码时,它运行良好,但是我希望保存的图像没有出现在我试图保存它们的目录中。
gen = image.ImageDataGenerator(rotation_range=17, width_shift_range=0.12,
height_shift_range=0.12, zoom_range=0.12, horizontal_flip=True, dim_ordering='th')
batches = gen.flow_from_directory(path+'train', target_size=(224,224),
class_mode='categorical', shuffle=False, batch_size=batch_size, save_to_dir=path+'augmented', save_prefix='hi')
我觉得我一定没有正确使用这个功能。知道我做错了什么吗?
gen.flow_from_directory
给你一个发电机。图像并不是真正生成的。为了获取图像,您可以遍历生成器。例如
i = 0
for batch in gen.flow_from_directory(path+'train', target_size=(224,224),
class_mode='categorical', shuffle=False, batch_size=batch_size,
save_to_dir=path+'augmented', save_prefix='hi'):
i += 1
if i > 20: # save 20 images
break # otherwise the generator would loop indefinitely
它只是一个声明,你必须使用那个生成器,例如.next()
batches.next()
然后您将在 path+'augmented'