简体   繁体   English

Keras:如何使用`image_dataset_from_directory`加载测试集?

[英]Keras: How to use `image_dataset_from_directory` to load test set?

I am using tf.keras.preprocessing.image_dataset_from_directory to load dataset as follows,我正在使用tf.keras.preprocessing.image_dataset_from_directory加载数据集,如下所示,

train_dataset = tf.keras.preprocessing.image_dataset_from_directory(train_dir, 
                                                                    labels='inferred', 
                                                                    label_mode='categorical',
                                                                    batch_size=32,
                                                                    image_size=(224, 224))


val_dataset = tf.keras.preprocessing.image_dataset_from_directory(val_dir, 
                                                                  labels='inferred', 
                                                                  label_mode='categorical',
                                                                  batch_size=32,
                                                                  image_size=(224, 224))

However, when I check the document looks like this argument labels seem to be a must-have one, but my test data has no labels, so how can I load test data?但是,当我检查文档时,这个参数labels似乎是必须的,但我的测试数据没有标签,那么我该如何加载测试数据呢? Is there a convenient and unified way to do this?有没有方便统一的方法来做到这一点?

If your data isn't labeled, I don't think you can call it the test set , since you won't be able to evaluate the performance of your algorithm using it.如果您的数据未标记,我认为您不能将其称为测试集,因为您将无法使用它评估算法的性能。

The argument you're looking for is label_mode , see the documentation .您要查找的参数是label_mode ,请参阅documentation If you set it to label_model=None , it will not return a target;如果将其设置为label_model=None ,它将不会返回目标;

label_mode : 'int' : means that the labels are encoded as integers (eg for sparse_categorical_crossentropy loss). label_mode : 'int' : 表示标签被编码为整数(例如对于 sparse_categorical_crossentropy 损失)。 'categorical' means that the labels are encoded as a categorical vector (eg for categorical_crossentropy loss). 'categorical'表示标签被编码为分类向量(例如,用于 categorical_crossentropy 损失)。 'binary' means that the labels (there can be only 2) are encoded as float32 scalars with values 0 or 1 (eg for binary_crossentropy). 'binary'表示标签(只能有 2 个)被编码为 float32 标量,值为 0 或 1(例如 binary_crossentropy)。 None (no labels).(无标签)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 keras image_dataset_from_directory 与自定义结构一起使用? - How to use keras image_dataset_from_directory with custom structures? 如何查看keras的image_dataset_from_directory function生成的数据集? - How to view the dataset generated by the image_dataset_from_directory function of keras? Keras:`image_dataset_from_directory` 中标签的一次性使用 - Keras: one-hot for labels in `image_dataset_from_directory` 如何使用 tf.keras.utils.image_dataset_from_directory 加载测试数据集? - How to use tf.keras.utils.image_dataset_from_directory to load test dataset? 如何从 Keras 中的 image_dataset_from_directory() 从 MapDataset 附加或获取文件名? - How to attach or get filenames from MapDataset from image_dataset_from_directory() in Keras? Keras 方法 image_dataset_from_directory() 如何区分 X 和 Y 数据? - How does the Keras method image_dataset_from_directory() distinguish X and Y data? 丢失 function 与 image_dataset_from_directory 一起使用 - Loss function to use with image_dataset_from_directory 如何理解 image_dataset_from_directory() 并将其用作 X、y 输入? - How understand image_dataset_from_directory() and use it as X, y input? 如何正确使用 tfa.metrics.F1Score 和 image_dataset_from_directory? - How to use tfa.metrics.F1Score with image_dataset_from_directory correctly? 导入错误:无法从“tensorflow.keras.preprocessing”(未知位置)导入名称“image_dataset_from_directory” - ImportError: cannot import name 'image_dataset_from_directory' from 'tensorflow.keras.preprocessing' (unknown location)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM