Reputation: 1126
Apologies if this has an obvious answer, I feel like it should. When using Tensorflow Datasets the labels are automatically integers but you can display them via the API to get the string mapping. For example in CIFAR10 7 corresponds to horse. How can I get these mappings? Do I have to download the dataset and get them from the folder/dir names? Or is there another way?
Cheers
Edit: as Amel pointed out below, the reason why I think it must be accessible somehow is because when calling show examples, the class names show up next to the integer labels.
Upvotes: 0
Views: 522
Reputation: 116
you need to use train_ds.class_names (train_ds is the dataset)
for example:
class_names = train_ds.class_names
for images, labels in train_ds.take(1):
print(labels)
for i in range(0, 5):
print(labels[i])
print(class_names[labels[i]])
Here, you can see that labels[i] is a tensor with an integer and class_names[labels[i]] is the string corresponding.
Upvotes: 1