[英]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.