1

我正在尝试将我的增强图像保存在一个文件夹中,但循环正在执行无限次。我的文件夹中有 5000 张图像,但我得到的增强图像的数量是无限的。我的目标是获得相同数量的增强图像,即 5000。

谢谢

import numpy as np
from keras.preprocessing.image import ImageDataGenerator

datagen = ImageDataGenerator(rotation_range=90)

image_path = 'C:/Users/1/Desktop/DEEP/Dataset/Train/1training_c10882.png'

image = np.expand_dims(imageio.imread(image_path), 0)

save_here = 'D:/Augmented DATASET/'

generator = datagen.flow_from_directory('C:/Users/1/Desktop/DEEP/Dataset/Train',target_size=(224,224),
                                    batch_size = 256, class_mode = 'binary')

for inputs,outputs in generator:
    pass
4

1 回答 1

4

也许这会对你有所帮助。

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
datagen = ImageDataGenerator(shear_range=0.2, zoom_range=0.2) 

for f in filenames:
    img = load_img(f)  
    x = img_to_array(img) 
    # Reshape the input image 
    x = x.reshape((1, ) + x.shape)  
    i = 0

    # generate 5 new augmented images 
    for batch in datagen.flow(x, batch_size = 1, 
                      save_to_dir ='aug',  
                      save_prefix ='car', save_format ='jpeg'):
        i += 1
        if i > 5: 
            break
于 2020-01-24T18:00:50.250 回答