Keras image_dataset_from_directory 未找到图像 [英] Keras image_dataset_from_directory not finding images

查看:61
本文介绍了Keras image_dataset_from_directory 未找到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我有大约 5000 张图像的目录中加载数据(类型png").但是它返回一个错误,说当明显有图像时没有图像.这段代码:

I want to load the data from the directory where I have around 5000 images (type 'png'). But it returns me an error saying that there are no images when obviusly there are images. This code:

width=int(wb-wa)
height=int(hb-ha)
directory = '/content/drive/My Drive/Colab Notebooks/Hair/Images'
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    directory, labels=densitat, label_mode='int',
    color_mode='rgb', batch_size=32, image_size=(width, height), shuffle=True, seed=1,
    validation_split=0.2, subset='training', follow_links = False)

返回:

ValueError: Expected the lengths of `labels` to match the number of files in the target directory. len(labels) is 5588 while we found 0 files in /content/drive/My Drive/Colab Notebooks/Hair/Images.

我可以看到图像:带有图像的文件夹结构的 Colab 视图

问题出在哪里?我需要使用这个函数来批量加载数据,因为我有一个大数据集

Where is the problem? I need to use this function to load data in batchs as i have a large dataset

推荐答案

我找到了答案,所以我发帖以防它可能对某人有所帮助.

I have found the answer so I am posting in case it might help someone.

问题是路径,因为我使用的是带有图像的文件夹的路径,而我应该使用目录(上面的一个文件夹).

The problrem is the path, as I was using the path to the folder with the images whereas I should have used the directory (one folder above).

directory = '/content/drive/My Drive/Colab Notebooks/Hair'

请注意,/Hair"是包含我的图片的文件夹.

Note that '/Hair' is the folder with my images.

这篇关于Keras image_dataset_from_directory 未找到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆