【发布时间】:2021-07-12 18:24:06
【问题描述】:
我正在从数据集(使用 flow_from_dataframe 创建)中迭代图像,并希望使用 pyplot 及其相应的标签显示图像
training_dataset = train_dataset_gen.flow_from_dataframe(dataframe=train_df,
directory="./Data/train/",
x_col="file",
y_col="label",
shuffle=True,
batch_size=BATCH_SIZE,
target_size=IMG_SIZE,
class_mode="sparse",
subset="training")
我可以显示图像,但标签是 0 和 1 的数组。
for _ in range(len(training_dataset.filenames)):
image, label = training_dataset.next()
# display the image from the iterator
plt.imshow(image[0])
plt.title(training_dataset.)
plt.show()
如何获得真正的标签值?
这是通过反转字典来解决的:
class_names=training_dataset.class_indices
new_dict={}
for key, value in class_names.items():
new_dict[value]=key
【问题讨论】:
标签: tensorflow machine-learning computer-vision