【发布时间】:2021-04-23 04:33:00
【问题描述】:
图片文件夹结构如下:
train/
...batch0/
......file00.jpg
......file01.jpg
...batch1/
......file10.jpg
......file11.jpg
目录名称batch0 和batch1 不是标签,标签位于单独的文件中。问题是将这些图像加载到数据集中。函数image_dataset_from_directory('/batch0')、image_dataset_from_directory('/batch1') 不起作用。
错误:
ValueError: Expected the lengths of labels to match the number of files in the target directory. len(labels) is 2 while we found 0 files in ../train/batch0/.
【问题讨论】:
-
为什么要在文件夹本身中将图像分成批次?它抛出的错误是什么?
-
我有两种不成功的情况,一种成功的情况。 1)
image_dataset_from_directory('../train/batch0') Found 0 files belonging to 0 classes.2)labels_list=[0, 1] image_dataset_from_directory(train_dir, labels=labels_list) ValueError: Expected the lengths of labels to match the number of files in the target directory. len(labels) is 2 while we found 0 files in ../train/batch0/.3)成功情况:image_dataset_from_directory('../train/') Found 4 files belonging to 2 classes. -
啊,你需要使用相对路径,就像在成功的情况下一样,但问题是
image_dataset_from_directory假定目录是不同的类而不是批次。 -
image_dataset_from_directory有模式,可以通过参数labels开启/关闭。标签:“推断”(标签是从目录结构生成的),或者与目录中找到的图像文件数量相同大小的整数标签列表/元组。
标签: tensorflow keras tensorflow-datasets