Skip to content

Instantly share code, notes, and snippets.

@atqamar
Last active September 7, 2017 22:13
Show Gist options
  • Save atqamar/112112e3fb8ded4ace7e4c190dbef8df to your computer and use it in GitHub Desktop.
Save atqamar/112112e3fb8ded4ace7e4c190dbef8df to your computer and use it in GitHub Desktop.
TG labels to categories mapping
# here we list all relevant nums (label ids)
nums = [
1, 3, 4, 13, 19, 20, 26, 27, 34, 35, 52, 63, 72, 73, 74, 75, 77, 79, 80, 82,
83, 85, 89, 91, 93, 104, 106, 107, 109, 167, 168, 172, 190, 195, 196, 198, 203,
204, 205, 206, 208, 209, 215, 218, 219, 235, 246, 266, 271, 273, 288, 289, 290,
292, 293, 295, 296, 297, 299, 300, 301, 302, 303, 304, 306, 307, 308, 309, 310,
311, 312, 313, 319, 320, 326, 328, 329, 331, 332, 335, 336, 337, 338, 340, 341,
343, 344, 347, 348, 349, 350, 351, 352, 354, 355, 357, 358, 360, 361, 362, 363,
364, 366, 367, 369, 370, 371, 372, 373, 374, 375, 378, 379, 380, 382, 383, 385,
386, 388, 391, 393, 397, 398, 399, 420, 422, 427, 429, 434, 443, 444, 524, 530,
556, 589, 591, 593, 598, 603, 605, 606, 609, 610, 619, 620, 623, 624, 626, 629,
630, 636, 639, 640, 642, 643, 645, 646, 649, 650, 652, 653, 654, 655, 656, 657,
658, 659, 661, 663, 664, 665, 667, 669, 671, 672, 675, 676, 677, 678, 679, 680,
684, 686, 687, 688, 689, 690, 691, 693, 694, 695, 696, 698, 699, 701, 702, 703,
705, 707, 709, 710, 712, 713, 716, 720, 721, 723, 725, 728, 730, 731, 732, 733,
734, 735, 736, 738, 739, 740, 741, 743, 747, 750, 752, 756, 760, 761, 763, 764,
765, 766, 767, 768, 769, 771, 772, 773, 774, 775, 777, 779, 780, 781, 783, 784,
785, 789, 792, 793, 796, 798, 799, 800, 801, 802, 804, 810, 811, 813, 814, 815,
816, 817, 819, 821, 822, 823, 824, 826, 827, 828, 832, 833, 835, 837, 838, 839,
840, 841, 842, 844, 845, 847, 848, 849, 855, 862, 864, 876, 886, 887, 888, 889,
890, 891, 892, 893, 894, 895,
]
# here we list cats (category ids) associated with the above nums
cats = [
None, 6, 5, 28, 1, 9, 18, 1, 1, 16, 31, 33, 18, None, 31, 2, None, 2, 26, 7, 8,
16, 19, None, 2, 33, 12, 12, 6, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, 12, 28, 2, 10, 16,
5, 19, 31, 15, 5, 20, 12, 19, 19, None, None, 11, 2, None, 10, 16, 10, 12, 25,
19, 2, 14, 6, 2, None, 19, 19, None, 3, 4, None, None, None, 28, None, 5, 19,
19, 13, 19, None, None, None, None, 14, 12, 14, None, 21, 31, 4, None, None, 19,
None, 25, 25, 25, None, 6, 11, 12, None, None, None, 2, 10, 12, 19, 2, None, 12,
6, 24, 19, 31, 12, 31, 19, None, None, 14, 14, 19, 7, 28, 31, 14, 11, 15, None,
10, 14, None, None, 20, None, 19, None, None, 12, 12, None, None, None, None,
None, 28, 31, 6, None, 11, 6, None, 12, 6, 2, 16, 12, 12, 2, 6, 10, None, 6, 19,
2, 19, 6, None, 6, 13, 31, 23, None, None, None, None, None, None, 7, 34, None,
3, 21, 11, None, 19, None, None, 19, 6, 3, None, 22, None, 6, 12, None, 16, 6,
6, 1, 18, None, None, 19, None, 3, 26, 12, None, None, 2, 28, 11, 2, 6, 14, 18,
3, 20, None, 17, None, 10, 6, 6, 12, None, 3, 4, 12, 22, 6, 19, 31, 26, 12, 28,
12, 6, 19, 6, 12, 12, None, 1, 17, 15, 15, 15, 11, 11, 19, 19, 33, 15, None, 28,
10, 19, None, 11, 19, 14, 12, 6, None, None, None, 31, 28, 12, None, None, 6,
None, None, None, None, None, None, None, None, 28, 19,
]
# mapping of nums to names
def get_num2name():
import requests
url = 'https://s3.amazonaws.com/threadgenius-models/canonical_labels.txt'
r = requests.get(url)
num2name = {}
for line in r.text.strip().split('\n'):
num, name = line.strip().split(' ', 1)
name = name.replace('**', '').replace('::', ' ')
num2name[int(num)] = name
return num2name
# cat names listed in order of category id, mapping of cats to names made below
cat_names = [
'__background__', # first index is bg, which we ignore
'top-sleeveless', 'bag-other', 'earring', 'ring', 'skirt', 'dress', 'bra',
'belt', 'backpack', 'pants-long', 'eyewear', 'top-short/long-sleeve', 'hat',
'outerwear-heavy', 'watch', 'pants-short', 'wallet', 'bikini',
'footwear-regular', 'necklace', 'scarf', 'suit-blazer', 'socks', 'jumpsuit',
'gloves', 'underwear-bottom', 'cufflinks', 'outerwear-light', 'bracelet', 'tie',
'footwear-tall', 'bow-tie', 'top-button-up', 'headband',
]
num2name = get_num2name()
cat2name = {cat: name for cat, name in enumerate(cat_names) if cat > 0}
num2cat = {num: cat for num, cat in zip(nums, cats) if cat is not None}
cat2num = {}
cat_name2num_name = {}
for num, cat in num2cat.iteritems():
if cat in cat2num:
cat2num[cat].append(num)
cat_name2num_name[cat2name[cat]].append(num2name[num])
else:
cat2num[cat] = [num]
cat_name2num_name[cat2name[cat]] = [num2name[num]]
num_name2cat_name = {}
for num, cat in num2cat.iteritems():
num_name2cat_name[num2name[num]] = cat2name[cat]
# call this function to get a print out of the mappings for inspection
def print_cat_name2num_name():
for cat in sorted(cat2num):
print 'CAT [%s] [%s]' % (cat, cat2name[cat])
for num in cat2num[cat]:
print ' [%s] [%s]' % (num, num2name[num])
print
# you might be interested in using the following mappings
# - cat2num
# - cat_name2num_name
# - num2cat
# - num_name2cat_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment