3

So here I want to apply augmentation to a dataset of images to increase the size of the Dataset but I keep getting error.

Here is the code :

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

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

image_directory = r'/gdrive/My Drive/HealthySkin/'
SIZE= 128
dataset = []

my_images = os.listdir(image_directory)
for i ,image_name in enumerate(my_images):
       if (image_name.split(".")[1] == 'jpeg'):
        image = io.imread(image_directory + image_name)
        image = Image.fromarray(image,'RGB')
        image = Image.resize((SIZE,SIZE))
        dataset.append(np.array(image))

x = np.array(dataset)


i = 0
for batch in datagen.flow(x, batch_size=16 , save_to_dir='Aug', save_prefix='1', save_format='jpeg'):
    i += 1
    if i > 20:
        break** 

The error says "ValueError: ('Input data in NumpyArrayIterator should have rank 4. You passed an array with shape', (0,))" For the last loop How can I fix the error ?

Fatema
  • 31
  • 1

0 Answers0