tf.keras.preprocessing.image_dataset_from_directory Value Error: No images found

Viewed 5582

belos is my code to ensure that the folder has images, but tf.keras.preprocessing.image_dataset_from_directory returns no images found. What did I do wrong? Thanks.

DATASET_PATH = pathlib.Path('C:\\Users\\xxx\\Documents\\images')
image_count = len(list(DATASET_PATH.glob('.\\*.jpg')))
print(image_count)

output = 2715

batch_size = 4
img_height = 32
img_width = 32

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    DATASET_PATH.name,
    validation_split=0.8,
    subset="training",
    seed=123,
    image_size=(img_height, img_width),
    batch_size=batch_size)

output:

Found 0 files belonging to 0 classes.
Using 0 files for training.
Traceback (most recent call last):
  File ".\tensorDataPreProcessed.py", line 23, in <module>
    batch_size=batch_size)
  File "C:\Users\xxx\Anaconda3\envs\xxx\lib\site-packages\tensorflow\python\keras\preprocessing\image_dataset.py", line 200, in image_dataset_from_directory
    raise ValueError('No images found.')
ValueError: No images found.
1 Answers

There are two issues here, firstly image_dataset_from_directory requires subfolders for each of the classes within the directory. This way it can automatically identify and assign class labels to images.

So the standard folder structure for TF is:

data
|
|___train
|      |___class_1
|      |___class_2
|
|___validation
|      |___class_1
|      |___class_2
|
|___test(optional)
       |___class_1
       |___class_2

The other issue is that you are attempting to create a model using only one class which is not a way to go. The model needs to be able to differentiate between the class you are trying to generate using GAN but to do this it needs a sample of images that do not belong to this class.

Related