ValueError: ('Input data in `NumpyArrayIterator` should have rank 4. You passed an array with shape', (0,))

Viewed 34

previous session it runs successfully, but when I run it for the second time an error like this appears. ValueError: ('Input data in `NumpyArrayIterator` should have rank 4. You passed an array with shape', (0,)) ` I want to augmentate the images and save them. Anyone can help me to solve this error?

Here is my full code:

IMAGES_PATH = 'Tensorflow/workspace/images/train'

from tensorflow.keras.preprocessing.image import ImageDataGenerator
from matplotlib.pyplot import imread, imshow, subplot, show
import numpy as np
import os
from PIL import Image
from skimage import io

datagen = ImageDataGenerator(horizontal_flip=True, rotation_range=30, fill_mode='nearest')

image_directory = (IMAGES_PATH + '/ID15/')
dataset=[]

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

x = np.array(dataset)
i = 0
for batch in datagen.flow(x, 
                         save_to_dir = (IMAGES_PATH + '/data'),
                         save_prefix='image',
                         save_format='jpg'):
    
    i+=1
    if i > 1: 
        break
0 Answers
Related