You have not to specified the parameter label_mode
. In order to use SparseCategoricalCrossentropy
as the loss function you need to set it to int
.
If you do not specify it then it is set to None
as per the documentation.
You need to also specify the parameter labels
to be the inferred
based on the structure of the directory that you read the images from.
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
labels="inferred",
label_mode="int",
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
labels="inferred",
label_mode="int",
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…