将训练标签传递给 tf.keras.preprocessing.image_dataset_from_directory 不起作用

jly*_*lyh 6 python machine-learning keras image-classification

我正在尝试将数据加载到 Colab 笔记本中,其中(平面)目录包含一堆 jpg 图像,标签类包含在单独的 csv 文件中,使用 tf.keras.preprocessing.image_dataset_from_directory。

根据文档:

Either "inferred" (labels are generated from the directory structure), or a list/tuple of integer labels of the same size as the number of image files found in the directory. Labels should be sorted according to the alphanumeric order of the image file paths (obtained via os.walk(directory) in Python).

我使用 Pandas 读取 csv 并使用以下内容将其转换为列表,并将 train_labels 作为标签参数传入:

labels = pd.read_csv(_URL)
train_labels = labels.values[:,1].tolist()
print("Total labels:", len(train_labels))
print(train_labels)
>>> Total labels: 1164
>>> [1, 0, 1, 1, 1, 2, 0, ... ]
train_dataset = image_dataset_from_directory(directory=train_dir,
                                         labels=train_labels,
                                         label_mode='int',
                                         shuffle=True,
                                         batch_size=BATCH_SIZE,
                                         image_size=IMG_SIZE)
Run Code Online (Sandbox Code Playgroud)

但是,在运行单元时,输出为:

Found 1164 files belonging to 1 classes.
Run Code Online (Sandbox Code Playgroud)

我在类列表中传递的格式是否有问题,或者在标签类生效之前是否需要进行其他设置?