Keras image_dataset_from_directory 找不到图像
Keras image_dataset_from_directory not finding images
我想从我有大约 5000 张图像的目录中加载数据(类型 'png')。但是它 returns 给我一个错误,说明明有图像却没有图像。
此代码:
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)
Returns:
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 view of the folder structure with the images
问题出在哪里?我需要使用这个函数来批量加载数据,因为我有一个很大的数据集
我找到了答案所以我发帖以防它可能对某人有帮助。
问题是路径,因为我使用的是带有图像的文件夹的路径,而我应该使用目录(上面的一个文件夹)。
directory = '/content/drive/My Drive/Colab Notebooks/Hair'
请注意,“/Hair”是包含我的图像的文件夹。
如果上面接受的解决方案不能解决您的问题,可能是因为您正在尝试加载扩展名为 .tif
的 TIFF 图像。结果 image_dataset_from_directory
唯一允许的格式是 ('.bmp', '.gif', '.jpeg', '.jpg', '.png')
我想从我有大约 5000 张图像的目录中加载数据(类型 'png')。但是它 returns 给我一个错误,说明明有图像却没有图像。 此代码:
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)
Returns:
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 view of the folder structure with the images
问题出在哪里?我需要使用这个函数来批量加载数据,因为我有一个很大的数据集
我找到了答案所以我发帖以防它可能对某人有帮助。
问题是路径,因为我使用的是带有图像的文件夹的路径,而我应该使用目录(上面的一个文件夹)。
directory = '/content/drive/My Drive/Colab Notebooks/Hair'
请注意,“/Hair”是包含我的图像的文件夹。
如果上面接受的解决方案不能解决您的问题,可能是因为您正在尝试加载扩展名为 .tif
的 TIFF 图像。结果 image_dataset_from_directory
唯一允许的格式是 ('.bmp', '.gif', '.jpeg', '.jpg', '.png')