如何处理和保存相同的数据扩充到多个输入

时间:2019-06-22 22:56:30

标签: keras save offline data-augmentation multiple-input

我正在尝试处理数据扩展并将其保存到由500个类组成的数据集中,每个类10个图像。我的数据集是一个立体数据集,这意味着每个场景有两个视图。换句话说,它具有以下架构:

->left
|_____0001
|_____0002
   ...
|_____0500

->right
|_____0001
|_____0002
   ...
|_____0500

我想对左右输入执行相同的脱机数据扩充,并将它们保存在原始图像的相同目录中。这是我的代码:

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
import os
import numpy as np


data_path_l=".\TRAIN\left\"
data_path_r=".\TRAIN\right\"

#Create a generator
input_imgen =ImageDataGenerator(rotation_range=15,horizontal_flip=True,
                                fill_mode='nearest'

#Get all the images in the left sub-directories
for file, subfolder, folder in os.walk(data_path_l):
      for fo in folder:
          path = os.path.join(file,fo)
          img = load_img(path)
          X = img_to_array(img)  
          X = np.expand_dims(X, 0)  
          i = 0
          for batch in data_generator.flow(X,save_to_dir=file,save_prefix='aug',save_format='png',shuffle=False,batch_size=1,seed=666):
              i += 1
              if i % 3 == 0:  # Generate three transformed pictures
                  break       # To avoid generator to loop indefinitely

 #Get all the images in the right sub-directories
for file, subfolder, folder in os.walk(data_path_r):
      for fo in folder:
          path = os.path.join(file,fo)
          img = load_img(path)
          X = img_to_array(img)  
          X = np.expand_dims(X, 0)  
          i = 0
          for batch in data_generator.flow(X,save_to_dir=file,save_prefix='aug',save_format='png',shuffle=False,batch_size=1,seed=666):
              i += 1
              if i % 3 == 0:  # Generate three transformed pictures
                  break       # To avoid generator to loop indefinitely

问题在于,先前的代码对左右一对执行相同的转换,但仅针对每个类中的最后一个图像! 谁能为我提供解决方案或向我提出另一种执行任务的方法?

0 个答案:

没有答案