Search code examples
jsondatasetlabeltensorflow-datasets

CIFAR-100 - I can't find the file: "cifar100_fine_labels.json"


I'm a newbie and I'm making a tutorial.

I can't find the file: "cifar100_fine_labels.json" In the tutorial, the guy already has this file (cifar100_fine_labels.json) and says you can download it from this site (https://www.cs.toronto.edu/~kriz/cifar.html), but I downloaded this dataset from this site: "CIFAR-10 python version" and i can't find this file.

In practice do this:

# I downloaded the Cifar-100 dataset:
(train_images, train_labels), (test_images, test_labels) = cifar100.load_data(label_mode='fine')

# Load the list of labels from a JSON file
import json
with open('cifar100_fine_labels.json', 'r') as fine_labels:
    cifar100_fine_labels = json.load(fine_labels)

and it doesn't work becouse I don't have: 'cifar100_fine_labels.json'.

Can I download it from somewhere or do I have to extract it myself from the dataset?

Thanks for the answer

I would like to get where I can find this file or how to extract it from the dataset.


Solution

  • In the link you send there are two datasets, "CIFAR-10" at the top, and when you scroll down there is "CIFAR-100". It sounds like you downloaded the first dataset, but actually need the second one.

    So scroll down and download CIFAR-100 python version and the json should be there :)

    Edit: After downloading the file myself I realize this might not fix your problem. Here is some code to build such a json. (provided you downloaded and unzipped the file)

    # from cifar link, changed for python3
    def unpickle(file):
        import pickle
        with open(file, 'rb') as fo:
            dict = pickle.load(fo)
        return dict
    
    path = "cifar-100-python/meta"
    
    label_translation = unpickle(path)
    
    with open("cifar100_fine_labels.json", "w") as f:
        json.dump(label_translation, f)