Skip to content

Instantly share code, notes, and snippets.

@adam-dziedzic
Created November 19, 2020 15:39
Show Gist options
  • Save adam-dziedzic/4322df7fc26a1e75bee3b355b10e30bc to your computer and use it in GitHub Desktop.
Save adam-dziedzic/4322df7fc26a1e75bee3b355b10e30bc to your computer and use it in GitHub Desktop.
Mappings between fine (classes) and coarse labels (superclasses) for CIFAR100.
import pprint as pp
fine_labels = [
'apple', # id 0
'aquarium_fish',
'baby',
'bear',
'beaver',
'bed',
'bee',
'beetle',
'bicycle',
'bottle',
'bowl',
'boy',
'bridge',
'bus',
'butterfly',
'camel',
'can',
'castle',
'caterpillar',
'cattle',
'chair',
'chimpanzee',
'clock',
'cloud',
'cockroach',
'couch',
'crab',
'crocodile',
'cup',
'dinosaur',
'dolphin',
'elephant',
'flatfish',
'forest',
'fox',
'girl',
'hamster',
'house',
'kangaroo',
'computer_keyboard',
'lamp',
'lawn_mower',
'leopard',
'lion',
'lizard',
'lobster',
'man',
'maple_tree',
'motorcycle',
'mountain',
'mouse',
'mushroom',
'oak_tree',
'orange',
'orchid',
'otter',
'palm_tree',
'pear',
'pickup_truck',
'pine_tree',
'plain',
'plate',
'poppy',
'porcupine',
'possum',
'rabbit',
'raccoon',
'ray',
'road',
'rocket',
'rose',
'sea',
'seal',
'shark',
'shrew',
'skunk',
'skyscraper',
'snail',
'snake',
'spider',
'squirrel',
'streetcar',
'sunflower',
'sweet_pepper',
'table',
'tank',
'telephone',
'television',
'tiger',
'tractor',
'train',
'trout',
'tulip',
'turtle',
'wardrobe',
'whale',
'willow_tree',
'wolf',
'woman',
'worm',
]
mapping_coarse_fine = {
'aquatic mammals': ['beaver', 'dolphin', 'otter', 'seal', 'whale'],
'fish': ['aquarium_fish', 'flatfish', 'ray', 'shark', 'trout'],
'flowers': ['orchid', 'poppy', 'rose', 'sunflower', 'tulip'],
'food containers': ['bottle', 'bowl', 'can', 'cup', 'plate'],
'fruit and vegetables': ['apple', 'mushroom', 'orange', 'pear',
'sweet_pepper'],
'household electrical device': ['clock', 'computer_keyboard', 'lamp',
'telephone', 'television'],
'household furniture': ['bed', 'chair', 'couch', 'table', 'wardrobe'],
'insects': ['bee', 'beetle', 'butterfly', 'caterpillar', 'cockroach'],
'large carnivores': ['bear', 'leopard', 'lion', 'tiger', 'wolf'],
'large man-made outdoor things': ['bridge', 'castle', 'house', 'road',
'skyscraper'],
'large natural outdoor scenes': ['cloud', 'forest', 'mountain', 'plain',
'sea'],
'large omnivores and herbivores': ['camel', 'cattle', 'chimpanzee',
'elephant', 'kangaroo'],
'medium-sized mammals': ['fox', 'porcupine', 'possum', 'raccoon', 'skunk'],
'non-insect invertebrates': ['crab', 'lobster', 'snail', 'spider', 'worm'],
'people': ['baby', 'boy', 'girl', 'man', 'woman'],
'reptiles': ['crocodile', 'dinosaur', 'lizard', 'snake', 'turtle'],
'small mammals': ['hamster', 'mouse', 'rabbit', 'shrew', 'squirrel'],
'trees': ['maple_tree', 'oak_tree', 'palm_tree', 'pine_tree',
'willow_tree'],
'vehicles 1': ['bicycle', 'bus', 'motorcycle', 'pickup_truck', 'train'],
'vehicles 2': ['lawn_mower', 'rocket', 'streetcar', 'tank', 'tractor'],
}
def print_fine_labels():
for id, label in enumerate(fine_labels):
print(id, " ", label)
def new_dicts():
# fine label name -> id of fine label
fine_id = dict()
# id of fine label -> fine label name
id_fine = dict()
for id, label in enumerate(fine_labels):
fine_id[label] = id
id_fine[id] = label
# coarse label name -> id of coarse label
coarse_id = dict()
# id of coarse label -> name of the coarse label
id_coarse = dict()
# name of fine label -> name of coarse label
fine_coarse = dict()
# id of fine label -> id of coarse label
fine_id_coarse_id = dict()
# id of coarse label -> id of fine label
coarse_id_fine_id = dict()
for id, (coarse, fines) in enumerate(mapping_coarse_fine.items()):
coarse_id[coarse] = id
id_coarse[id] = coarse
fine_labels_ids = []
for fine in fines:
fine_coarse[fine] = coarse
fine_label_id = fine_id[fine]
fine_id_coarse_id[fine_label_id] = id
fine_labels_ids.append(fine_label_id)
coarse_id_fine_id[id] = fine_labels_ids
dicts = ['fine_id', 'id_fine', 'coarse_id', 'id_coarse', 'fine_coarse',
'fine_id_coarse_id', 'coarse_id_fine_id']
for dic in dicts:
dic_value = locals()[dic]
print(dic + ' = ')
pp.pprint(dic_value)
if __name__ == "__main__":
print_fine_labels()
pp.pprint(mapping_coarse_fine)
new_dicts()
@adam-dziedzic
Copy link
Author

adam-dziedzic commented Nov 19, 2020

Output:
0 apple
1 aquarium_fish
2 baby
3 bear
4 beaver
5 bed
6 bee
7 beetle
8 bicycle
9 bottle
10 bowl
11 boy
12 bridge
13 bus
14 butterfly
15 camel
16 can
17 castle
18 caterpillar
19 cattle
20 chair
21 chimpanzee
22 clock
23 cloud
24 cockroach
25 couch
26 crab
27 crocodile
28 cup
29 dinosaur
30 dolphin
31 elephant
32 flatfish
33 forest
34 fox
35 girl
36 hamster
37 house
38 kangaroo
39 computer_keyboard
40 lamp
41 lawn_mower
42 leopard
43 lion
44 lizard
45 lobster
46 man
47 maple_tree
48 motorcycle
49 mountain
50 mouse
51 mushroom
52 oak_tree
53 orange
54 orchid
55 otter
56 palm_tree
57 pear
58 pickup_truck
59 pine_tree
60 plain
61 plate
62 poppy
63 porcupine
64 possum
65 rabbit
66 raccoon
67 ray
68 road
69 rocket
70 rose
71 sea
72 seal
73 shark
74 shrew
75 skunk
76 skyscraper
77 snail
78 snake
79 spider
80 squirrel
81 streetcar
82 sunflower
83 sweet_pepper
84 table
85 tank
86 telephone
87 television
88 tiger
89 tractor
90 train
91 trout
92 tulip
93 turtle
94 wardrobe
95 whale
96 willow_tree
97 wolf
98 woman
99 worm
{'aquatic mammals': ['beaver', 'dolphin', 'otter', 'seal', 'whale'],
'fish': ['aquarium_fish', 'flatfish', 'ray', 'shark', 'trout'],
'flowers': ['orchid', 'poppy', 'rose', 'sunflower', 'tulip'],
'food containers': ['bottle', 'bowl', 'can', 'cup', 'plate'],
'fruit and vegetables': ['apple',
'mushroom',
'orange',
'pear',
'sweet_pepper'],
'household electrical device': ['clock',
'computer_keyboard',
'lamp',
'telephone',
'television'],
'household furniture': ['bed', 'chair', 'couch', 'table', 'wardrobe'],
'insects': ['bee', 'beetle', 'butterfly', 'caterpillar', 'cockroach'],
'large carnivores': ['bear', 'leopard', 'lion', 'tiger', 'wolf'],
'large man-made outdoor things': ['bridge',
'castle',
'house',
'road',
'skyscraper'],
'large natural outdoor scenes': ['cloud',
'forest',
'mountain',
'plain',
'sea'],
'large omnivores and herbivores': ['camel',
'cattle',
'chimpanzee',
'elephant',
'kangaroo'],
'medium-sized mammals': ['fox', 'porcupine', 'possum', 'raccoon', 'skunk'],
'non-insect invertebrates': ['crab', 'lobster', 'snail', 'spider', 'worm'],
'people': ['baby', 'boy', 'girl', 'man', 'woman'],
'reptiles': ['crocodile', 'dinosaur', 'lizard', 'snake', 'turtle'],
'small mammals': ['hamster', 'mouse', 'rabbit', 'shrew', 'squirrel'],
'trees': ['maple_tree', 'oak_tree', 'palm_tree', 'pine_tree', 'willow_tree'],
'vehicles 1': ['bicycle', 'bus', 'motorcycle', 'pickup_truck', 'train'],
'vehicles 2': ['lawn_mower', 'rocket', 'streetcar', 'tank', 'tractor']}
fine_id =
{'apple': 0,
'aquarium_fish': 1,
'baby': 2,
'bear': 3,
'beaver': 4,
'bed': 5,
'bee': 6,
'beetle': 7,
'bicycle': 8,
'bottle': 9,
'bowl': 10,
'boy': 11,
'bridge': 12,
'bus': 13,
'butterfly': 14,
'camel': 15,
'can': 16,
'castle': 17,
'caterpillar': 18,
'cattle': 19,
'chair': 20,
'chimpanzee': 21,
'clock': 22,
'cloud': 23,
'cockroach': 24,
'computer_keyboard': 39,
'couch': 25,
'crab': 26,
'crocodile': 27,
'cup': 28,
'dinosaur': 29,
'dolphin': 30,
'elephant': 31,
'flatfish': 32,
'forest': 33,
'fox': 34,
'girl': 35,
'hamster': 36,
'house': 37,
'kangaroo': 38,
'lamp': 40,
'lawn_mower': 41,
'leopard': 42,
'lion': 43,
'lizard': 44,
'lobster': 45,
'man': 46,
'maple_tree': 47,
'motorcycle': 48,
'mountain': 49,
'mouse': 50,
'mushroom': 51,
'oak_tree': 52,
'orange': 53,
'orchid': 54,
'otter': 55,
'palm_tree': 56,
'pear': 57,
'pickup_truck': 58,
'pine_tree': 59,
'plain': 60,
'plate': 61,
'poppy': 62,
'porcupine': 63,
'possum': 64,
'rabbit': 65,
'raccoon': 66,
'ray': 67,
'road': 68,
'rocket': 69,
'rose': 70,
'sea': 71,
'seal': 72,
'shark': 73,
'shrew': 74,
'skunk': 75,
'skyscraper': 76,
'snail': 77,
'snake': 78,
'spider': 79,
'squirrel': 80,
'streetcar': 81,
'sunflower': 82,
'sweet_pepper': 83,
'table': 84,
'tank': 85,
'telephone': 86,
'television': 87,
'tiger': 88,
'tractor': 89,
'train': 90,
'trout': 91,
'tulip': 92,
'turtle': 93,
'wardrobe': 94,
'whale': 95,
'willow_tree': 96,
'wolf': 97,
'woman': 98,
'worm': 99}
id_fine =
{0: 'apple',
1: 'aquarium_fish',
2: 'baby',
3: 'bear',
4: 'beaver',
5: 'bed',
6: 'bee',
7: 'beetle',
8: 'bicycle',
9: 'bottle',
10: 'bowl',
11: 'boy',
12: 'bridge',
13: 'bus',
14: 'butterfly',
15: 'camel',
16: 'can',
17: 'castle',
18: 'caterpillar',
19: 'cattle',
20: 'chair',
21: 'chimpanzee',
22: 'clock',
23: 'cloud',
24: 'cockroach',
25: 'couch',
26: 'crab',
27: 'crocodile',
28: 'cup',
29: 'dinosaur',
30: 'dolphin',
31: 'elephant',
32: 'flatfish',
33: 'forest',
34: 'fox',
35: 'girl',
36: 'hamster',
37: 'house',
38: 'kangaroo',
39: 'computer_keyboard',
40: 'lamp',
41: 'lawn_mower',
42: 'leopard',
43: 'lion',
44: 'lizard',
45: 'lobster',
46: 'man',
47: 'maple_tree',
48: 'motorcycle',
49: 'mountain',
50: 'mouse',
51: 'mushroom',
52: 'oak_tree',
53: 'orange',
54: 'orchid',
55: 'otter',
56: 'palm_tree',
57: 'pear',
58: 'pickup_truck',
59: 'pine_tree',
60: 'plain',
61: 'plate',
62: 'poppy',
63: 'porcupine',
64: 'possum',
65: 'rabbit',
66: 'raccoon',
67: 'ray',
68: 'road',
69: 'rocket',
70: 'rose',
71: 'sea',
72: 'seal',
73: 'shark',
74: 'shrew',
75: 'skunk',
76: 'skyscraper',
77: 'snail',
78: 'snake',
79: 'spider',
80: 'squirrel',
81: 'streetcar',
82: 'sunflower',
83: 'sweet_pepper',
84: 'table',
85: 'tank',
86: 'telephone',
87: 'television',
88: 'tiger',
89: 'tractor',
90: 'train',
91: 'trout',
92: 'tulip',
93: 'turtle',
94: 'wardrobe',
95: 'whale',
96: 'willow_tree',
97: 'wolf',
98: 'woman',
99: 'worm'}
coarse_id =
{'aquatic mammals': 0,
'fish': 1,
'flowers': 2,
'food containers': 3,
'fruit and vegetables': 4,
'household electrical device': 5,
'household furniture': 6,
'insects': 7,
'large carnivores': 8,
'large man-made outdoor things': 9,
'large natural outdoor scenes': 10,
'large omnivores and herbivores': 11,
'medium-sized mammals': 12,
'non-insect invertebrates': 13,
'people': 14,
'reptiles': 15,
'small mammals': 16,
'trees': 17,
'vehicles 1': 18,
'vehicles 2': 19}
id_coarse =
{0: 'aquatic mammals',
1: 'fish',
2: 'flowers',
3: 'food containers',
4: 'fruit and vegetables',
5: 'household electrical device',
6: 'household furniture',
7: 'insects',
8: 'large carnivores',
9: 'large man-made outdoor things',
10: 'large natural outdoor scenes',
11: 'large omnivores and herbivores',
12: 'medium-sized mammals',
13: 'non-insect invertebrates',
14: 'people',
15: 'reptiles',
16: 'small mammals',
17: 'trees',
18: 'vehicles 1',
19: 'vehicles 2'}
fine_coarse =
{'apple': 'fruit and vegetables',
'aquarium_fish': 'fish',
'baby': 'people',
'bear': 'large carnivores',
'beaver': 'aquatic mammals',
'bed': 'household furniture',
'bee': 'insects',
'beetle': 'insects',
'bicycle': 'vehicles 1',
'bottle': 'food containers',
'bowl': 'food containers',
'boy': 'people',
'bridge': 'large man-made outdoor things',
'bus': 'vehicles 1',
'butterfly': 'insects',
'camel': 'large omnivores and herbivores',
'can': 'food containers',
'castle': 'large man-made outdoor things',
'caterpillar': 'insects',
'cattle': 'large omnivores and herbivores',
'chair': 'household furniture',
'chimpanzee': 'large omnivores and herbivores',
'clock': 'household electrical device',
'cloud': 'large natural outdoor scenes',
'cockroach': 'insects',
'computer_keyboard': 'household electrical device',
'couch': 'household furniture',
'crab': 'non-insect invertebrates',
'crocodile': 'reptiles',
'cup': 'food containers',
'dinosaur': 'reptiles',
'dolphin': 'aquatic mammals',
'elephant': 'large omnivores and herbivores',
'flatfish': 'fish',
'forest': 'large natural outdoor scenes',
'fox': 'medium-sized mammals',
'girl': 'people',
'hamster': 'small mammals',
'house': 'large man-made outdoor things',
'kangaroo': 'large omnivores and herbivores',
'lamp': 'household electrical device',
'lawn_mower': 'vehicles 2',
'leopard': 'large carnivores',
'lion': 'large carnivores',
'lizard': 'reptiles',
'lobster': 'non-insect invertebrates',
'man': 'people',
'maple_tree': 'trees',
'motorcycle': 'vehicles 1',
'mountain': 'large natural outdoor scenes',
'mouse': 'small mammals',
'mushroom': 'fruit and vegetables',
'oak_tree': 'trees',
'orange': 'fruit and vegetables',
'orchid': 'flowers',
'otter': 'aquatic mammals',
'palm_tree': 'trees',
'pear': 'fruit and vegetables',
'pickup_truck': 'vehicles 1',
'pine_tree': 'trees',
'plain': 'large natural outdoor scenes',
'plate': 'food containers',
'poppy': 'flowers',
'porcupine': 'medium-sized mammals',
'possum': 'medium-sized mammals',
'rabbit': 'small mammals',
'raccoon': 'medium-sized mammals',
'ray': 'fish',
'road': 'large man-made outdoor things',
'rocket': 'vehicles 2',
'rose': 'flowers',
'sea': 'large natural outdoor scenes',
'seal': 'aquatic mammals',
'shark': 'fish',
'shrew': 'small mammals',
'skunk': 'medium-sized mammals',
'skyscraper': 'large man-made outdoor things',
'snail': 'non-insect invertebrates',
'snake': 'reptiles',
'spider': 'non-insect invertebrates',
'squirrel': 'small mammals',
'streetcar': 'vehicles 2',
'sunflower': 'flowers',
'sweet_pepper': 'fruit and vegetables',
'table': 'household furniture',
'tank': 'vehicles 2',
'telephone': 'household electrical device',
'television': 'household electrical device',
'tiger': 'large carnivores',
'tractor': 'vehicles 2',
'train': 'vehicles 1',
'trout': 'fish',
'tulip': 'flowers',
'turtle': 'reptiles',
'wardrobe': 'household furniture',
'whale': 'aquatic mammals',
'willow_tree': 'trees',
'wolf': 'large carnivores',
'woman': 'people',
'worm': 'non-insect invertebrates'}
fine_id_coarse_id =
{0: 4,
1: 1,
2: 14,
3: 8,
4: 0,
5: 6,
6: 7,
7: 7,
8: 18,
9: 3,
10: 3,
11: 14,
12: 9,
13: 18,
14: 7,
15: 11,
16: 3,
17: 9,
18: 7,
19: 11,
20: 6,
21: 11,
22: 5,
23: 10,
24: 7,
25: 6,
26: 13,
27: 15,
28: 3,
29: 15,
30: 0,
31: 11,
32: 1,
33: 10,
34: 12,
35: 14,
36: 16,
37: 9,
38: 11,
39: 5,
40: 5,
41: 19,
42: 8,
43: 8,
44: 15,
45: 13,
46: 14,
47: 17,
48: 18,
49: 10,
50: 16,
51: 4,
52: 17,
53: 4,
54: 2,
55: 0,
56: 17,
57: 4,
58: 18,
59: 17,
60: 10,
61: 3,
62: 2,
63: 12,
64: 12,
65: 16,
66: 12,
67: 1,
68: 9,
69: 19,
70: 2,
71: 10,
72: 0,
73: 1,
74: 16,
75: 12,
76: 9,
77: 13,
78: 15,
79: 13,
80: 16,
81: 19,
82: 2,
83: 4,
84: 6,
85: 19,
86: 5,
87: 5,
88: 8,
89: 19,
90: 18,
91: 1,
92: 2,
93: 15,
94: 6,
95: 0,
96: 17,
97: 8,
98: 14,
99: 13}
coarse_id_fine_id =
{0: [4, 30, 55, 72, 95],
1: [1, 32, 67, 73, 91],
2: [54, 62, 70, 82, 92],
3: [9, 10, 16, 28, 61],
4: [0, 51, 53, 57, 83],
5: [22, 39, 40, 86, 87],
6: [5, 20, 25, 84, 94],
7: [6, 7, 14, 18, 24],
8: [3, 42, 43, 88, 97],
9: [12, 17, 37, 68, 76],
10: [23, 33, 49, 60, 71],
11: [15, 19, 21, 31, 38],
12: [34, 63, 64, 66, 75],
13: [26, 45, 77, 79, 99],
14: [2, 11, 35, 46, 98],
15: [27, 29, 44, 78, 93],
16: [36, 50, 65, 74, 80],
17: [47, 52, 56, 59, 96],
18: [8, 13, 48, 58, 90],
19: [41, 69, 81, 85, 89]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment