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

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

belos 是我确保文件夹中有图像的代码,但是 tf.keras.preprocessing.image_dataset_from_directory returns 没有找到图像。我做错了什么?谢谢

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

输出=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)

输出:

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.

这里有两个问题,首先,image_dataset_from_directory 需要目录中每个 class 的子文件夹。这样它就可以自动识别并为图像分配 class 个标签。

所以TF的标准文件夹结构是:

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

另一个问题是您试图仅使用一个 class 创建模型,这不是可行的方法。该模型需要能够区分您尝试使用 GAN 生成的 class,但要做到这一点,它需要 属于此 class.