Cifar_100 Targets Labels doubt

username: jmandivarapu1
cooked: <p>I am writing a way to assign coarse label (super class) for each label in the CIFAR 100 dataset.<br>
Is it like this below how they are assigned in pytorch while reading the data. like class 0 =beaver ,class 1 is dolphin …etc or anyother way?</p>
<p>(when I print classes it’s printing in alphabetical order in pytorch like <code> 'apple', 'aquarium_fish', 'baby', 'bear', 'beaver  which mean apple -0 , aquarium_fish 1 ,,etc ? AM I correct or now? or the below Image is correct?)</code>.</p>
<p>Just want to want to which one is correct. So I can create superclass for all labels.(went through images but as they are of small sizes it’s a bit confusion) . Any help appreciated.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/3/239ce0db0b27c9b8b9a8b30c7e00393dbb079a02.png" data-download-href="https://discuss.pytorch.org/uploads/default/239ce0db0b27c9b8b9a8b30c7e00393dbb079a02" title="Screen Shot 2020-05-15 at 1.28.11 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/3/239ce0db0b27c9b8b9a8b30c7e00393dbb079a02_2_690x335.png" alt="Screen Shot 2020-05-15 at 1.28.11 AM" data-base62-sha1="552OWRnNwLhUReqOGhRNkceqVW2" width="690" height="335" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/3/239ce0db0b27c9b8b9a8b30c7e00393dbb079a02_2_690x335.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/3/239ce0db0b27c9b8b9a8b30c7e00393dbb079a02_2_1035x502.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/2/3/239ce0db0b27c9b8b9a8b30c7e00393dbb079a02_2_1380x670.png 2x" data-dominant-color="EFEFEF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2020-05-15 at 1.28.11 AM</span><span class="informations">2222×1080 321 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: jmandivarapu1
cooked: <p>I did this not sure right or wrong. I read the test file downloaded by the pytorch dataloader</p>
<pre><code class="lang-auto">class Dictlist(dict):
    def __setitem__(self, key, value):
        try:
            self[key]
        except KeyError:
            super(Dictlist, self).__setitem__(key, [])
        self[key].append(value)

def unpickle(file):
    import pickle
    with open(file, 'rb') as fo:
        dict = pickle.load(fo, encoding='bytes')
    return dict
x=unpickle('cifar-100-python/test')
fine_to_coarse=Dictlist()

for i in range(0,len(x[b'coarse_labels'])):
    fine_to_coarse[x[b'coarse_labels'][i]]=x[ b'fine_labels'][i]
d=dict(fine_to_coarse)
for i in d.keys():
    d[i]=list(dict.fromkeys(d[i]))
</code></pre>
<p>Finally got the below</p>
<pre><code class="lang-auto">0: [72, 4, 95, 30, 55]
1: [73, 32, 67, 91, 1]
2: [92, 70, 82, 54, 62]
3: [16, 61, 9, 10, 28]
4: [51, 0, 53, 57, 83]
5: [40, 39, 22, 87, 86]
6: [20, 25, 94, 84, 5]
7: [14, 24, 6, 7, 18]
8: [43, 97, 42, 3, 88]
9: [37, 17, 76, 12, 68]
10: [49, 33, 71, 23, 60]
11: [15, 21, 19, 31, 38]
12: [75, 63, 66, 64, 34]
13: [77, 26, 45, 99, 79]
14: [11, 2, 35, 46, 98]
15: [29, 93, 27, 78, 44]
16: [65, 50, 74, 36, 80]
17: [56, 52, 47, 59, 96]
18: [8, 58, 90, 13, 48]
19: [81, 69, 41, 89, 85]
</code></pre>
<pre><code class="lang-auto">for i in range(0,20):
    print("Sub classes for Super class ",i,end=': ')
    for j in d[i]:
        print(dataset.cifar100.classes[j],end=',')
    print("")
</code></pre>
<p>Final Output is</p>
<pre><code class="lang-auto">Sub classes for Super class  0: seal,beaver,whale,dolphin,otter,
Sub classes for Super class  1: shark,flatfish,ray,trout,aquarium_fish,
Sub classes for Super class  2: tulip,rose,sunflower,orchid,poppy,
Sub classes for Super class  3: can,plate,bottle,bowl,cup,
Sub classes for Super class  4: mushroom,apple,orange,pear,sweet_pepper,
Sub classes for Super class  5: lamp,keyboard,clock,television,telephone,
Sub classes for Super class  6: chair,couch,wardrobe,table,bed,
Sub classes for Super class  7: butterfly,cockroach,bee,beetle,caterpillar,
Sub classes for Super class  8: lion,wolf,leopard,bear,tiger,
Sub classes for Super class  9: house,castle,skyscraper,bridge,road,
Sub classes for Super class  10: mountain,forest,sea,cloud,plain,
Sub classes for Super class  11: camel,chimpanzee,cattle,elephant,kangaroo,
Sub classes for Super class  12: skunk,porcupine,raccoon,possum,fox,
Sub classes for Super class  13: snail,crab,lobster,worm,spider,
Sub classes for Super class  14: boy,baby,girl,man,woman,
Sub classes for Super class  15: dinosaur,turtle,crocodile,snake,lizard,
Sub classes for Super class  16: rabbit,mouse,shrew,hamster,squirrel,
Sub classes for Super class  17: palm_tree,oak_tree,maple_tree,pine_tree,willow_tree,
Sub classes for Super class  18: bicycle,pickup_truck,train,bus,motorcycle,
Sub classes for Super class  19: streetcar,rocket,lawn_mower,tractor,tank,
</code></pre>
<p>I hope I am right as it matched the actual image from CIFAR website</p>