在Keras ImageDataGenerator流方法中遇到save_to_dir问题 [英] Having trouble with save_to_dir in Keras ImageDataGenerator flow method

查看:125
本文介绍了在Keras ImageDataGenerator流方法中遇到save_to_dir问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存我的ImageDataGenerator创建的增强图像,以便以后使用.当我执行以下代码时,它可以正常运行,但是我希望保存的图像没有显示在我试图保存它们的目录中.

I want to save the augmented images my ImageDataGenerator is creating so that I can use them later. When I execute the following code, it runs fine, but the images I was hoping to save do not show up in the directory I am trying to save them in.

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')

我觉得我一定不能正确使用此功能.知道我在做什么错吗?

I feel like I must not be using this feature correctly. Any idea what I'm doing wrong?

推荐答案

gen.flow_from_directory给您一个生成器.图像不是真正生成的.为了获得图像,您可以遍历生成器.例如

gen.flow_from_directory gives you a generator. The images are not really generated. In order to get the images, you can iterate through the generator. For example

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

这篇关于在Keras ImageDataGenerator流方法中遇到save_to_dir问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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