7

我正在尝试将数据加载到 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)

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

Found 1164 files belonging to 1 classes.

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

4

0 回答 0