【问题标题】:How to save images after data augmentation in a new folder without looping如何在不循环的情况下将数据扩充后的图像保存在新文件夹中
【发布时间】:2019-10-17 07:54:41
【问题描述】:

我正在尝试将我的增强图像保存在一个文件夹中,但循环正在无限次执行。我的文件夹中有 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

【问题讨论】:

    标签: python-3.x keras deep-learning infinite-loop data-augmentation


    【解决方案1】:

    也许这会对你有所帮助。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多