【问题标题】:tf.keras.preprocessing.image_dataset_from_directory Value Error: No images foundtf.keras.preprocessing.image_dataset_from_directory 值错误:未找到图像
【发布时间】: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_1C:\\Users\\xxx\\Documents\\images\\class_2
  • 嗨@pavel,如果我只有一门课怎么办?我还需要有一个 class_1 的子文件夹吗?
  • 你打算用一节课做什么?你打算如何训练模型?它将如何计算损失?至少你需要有一些类别的图像和不属于这个类别的图像,即“cars”和“not_cars”。
  • 感谢您指出这一点。是的。会有2节课。谢谢
  • 另外,我计划在课堂上使用一个 DCGAN。因此,我之前的评论。

标签: python image tensorflow tensorflow2.0 tf.keras


【解决方案1】:

这里有两个问题,首先image_dataset_from_directory 需要目录中每个类的子文件夹。通过这种方式,它可以自动识别图像并将类别标签分配给图像。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-01
    • 2017-08-27
    • 2017-11-18
    • 1970-01-01
    • 2020-05-17
    • 2015-12-02
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多