I have a directory for a dataset of images, I I want to transorm it to a numpy array in order to be able to fit an image generator to it. What I have tried to do is the following:
trainingset_temp = '/content/drive/My Drive/Colab Notebooks/Train'
testset = '/content/drive/My Drive/Colab Notebooks/Test'
import cv2
import glob
trainingset = []
files = glob.glob ('/content/drive/My Drive/Colab Notebooks/Train/Haze') # your
image path
for myFile in files:
image = cv2.imread (myFile)
trainingset.append (image)
files = glob.glob ('/content/drive/My Drive/Colab Notebooks/Train/Sunny')
for myFile in files:
image = cv2.imread (myFile)
trainingset.append (image)
files = glob.glob ('/content/drive/My Drive/Colab Notebooks/Train/Snowy')
for myFile in files:
image = cv2.imread (myFile)
trainingset.append (image)
files = glob.glob ('/content/drive/My Drive/Colab Notebooks/Train/Rainy')
for myFile in files:
image = cv2.imread (myFile)
trainingset.append (image)
trainingset = np.array(trainingset,dtype='float32')
but it gives me the following error message:
FileNotFoundError Traceback (most recent call last)
<ipython-input-44-2a679dbff06e> in <module>()
54 batch_size=batch_size,
55 class_mode="categorical",
---> 56 shuffle=True
57 )
58
1 frames
/usr/local/lib/python3.6/dist-
packages/keras_preprocessing/image/directory_iterator.py in __init__(self,
directory, image_data_generator, target_size, color_mode, classes,
class_mode, batch_size, shuffle, seed, data_format, save_to_dir,
save_prefix, save_format, follow_links, subset, interpolation, dtype)
104 if not classes:
105 classes = []
--> 106 for subdir in sorted(os.listdir(directory)):
107 if os.path.isdir(os.path.join(directory, subdir)):
108 classes.append(subdir)
FileNotFoundError: [Errno 2] No such file or directory: array([],
dtype=float32)
Can someone help me? Thanks in advance.