首页 > 解决方案 > 如何只增加每个图像一次并将其保存在目录中?

问题描述

我只想将每个图像增强一次并将其保存在目录中但是当我使用此代码时,生成和保存的图像的数量每次都会改变,我不知道为什么。你能帮忙吗?

datagen = ImageDataGenerator(
rotation_range=10,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest',
width_shift_range=0.1,
height_shift_range=0.1)

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

for f in aug_create_df['image_name']:
    img = load_img(merged_datapath + f)  
    x = img_to_array(img) 
    x = x.reshape((1, ) + x.shape)  
    i = 0
    for batch in train_datagen.flow(x, batch_size = 1, 
                      save_to_dir = augmented_pics_path,
                      save_prefix='aug',  
                      save_format ='jpg'):
        i += 1
        if i > 0: 
            break

标签: pythontensorflowkerasdata-augmentation

解决方案


推荐阅读