【发布时间】:2021-07-20 03:05:11
【问题描述】:
belos 是我的代码,用于确保文件夹有图像,但 tf.keras.preprocessing.image_dataset_from_directory 返回未找到图像。我做错什么了?谢谢。
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时,您的文件夹需要为每个类设置子文件夹,即C:\\Users\\xxx\\Documents\\images\\class_1、C:\\Users\\xxx\\Documents\\images\\class_2等 -
嗨@pavel,如果我只有一门课怎么办?我还需要有一个 class_1 的子文件夹吗?
-
你打算用一节课做什么?你打算如何训练模型?它将如何计算损失?至少你需要有一些类别的图像和不属于这个类别的图像,即“cars”和“not_cars”。
-
感谢您指出这一点。是的。会有2节课。谢谢
-
另外,我计划在课堂上使用一个 DCGAN。因此,我之前的评论。
标签: python image tensorflow tensorflow2.0 tf.keras