I use the following code to read all images in a folder and use them for image augmentation. load_images()
function reads all images as numpy array but when I use this function as input for image augmentation in the second part of the code, I get the error (setting an array element with a sequence). Any help is appreciated.
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from matplotlib.pyplot import imread, imshow, subplots, show
from matplotlib import pyplot as plt
import matplotlib.image as mpimg
import os
image_path = '/path/to/images/'
def load_images(image_path):
imagees = []
for filename in os.listdir(image_path):
img = mpimg.imread(os.path.join(image_path, filename))
if img is not None:
imagees.append(img)
return imagees
datagen = ImageDataGenerator(rotation_range=90, width_shift_range=0.3,
height_shift_range=0.3,shear_range=45.0, brightness_range=(0.1, 0.9),
zoom_range=[0.5, 1.5],channel_shift_range = 150.0, horizontal_flip=True, vertical_flip=True)
images = load_images(image_path)
images = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
save_here = '/path/to/images/'
datagen.fit(images)
for x, val in zip(datagen.flow(images,
save_to_dir=save_here,
save_prefix='aug',
save_format='png'),range(36)):
pass