-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_avelabel.py
64 lines (54 loc) · 1.9 KB
/
get_avelabel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from sklearn.metrics.pairwise import cosine_similarity
import os
import json
import numpy as np
def read_mat():
dataFile = 'path/imagelabels.mat'
data = scio.loadmat(dataFile)
def get_imagenet_labels():
"""Return list of imagnet labels
Returns:
[list(str)] -- list of imagnet labels
"""
with open('../imagenet_class_index.json', 'r') as f:
class_idx = json.load(f)
imagenet_labels = [class_idx[str(k)][1] for k in range(len(class_idx))]
return imagenet_labels
def get_flower_labels():
fname = 'path/flo_labels.txt'
with open(fname, 'r+', encoding='utf-8') as f:
s = [i[:-1].split(',') for i in f.readlines()]
flo_labels = [s[k][1] for k in range(len(s))]
return flo_labels
def get_inat_labels():
# fname = 'path/inat_label.txt'
# with open(fname, 'r+', encoding='utf-8') as f:
# s = [i.lower().replace('\n','') for i in f.readlines()]
# return s
"8000"
with open('path/categories.json', 'r') as f:
data = json.load(f)
name_list = [i['name'] for i in data]
filename = open('path/inat_8000categories.txt', 'w')
for i in name_list:
filename.write(i)
filename.write('\n')
filename.close()
return name_list
def get_cal_labels():
fname = 'path/cal_label.txt'
with open(fname, 'r+', encoding='utf-8') as f:
s = [i.replace('-',' ').replace('\n','') for i in f.readlines()]
return s
def get_sun_labels():
fname = 'path/ClassName.txt'
with open(fname, 'r+', encoding='utf-8') as f:
s = [i.replace('_',' ').replace('\n','').split('/')[-1] for i in f.readlines()]
return s
def get_nih_labels():
fname = 'path/nih.txt'
with open(fname, 'r+', encoding='utf-8') as f:
n = [i.replace('\n','').split(',')[-1] for i in f.readlines()]
with open(fname, 'r+', encoding='utf-8') as f:
s = [i.split(',')[0] for i in f.readlines()]
return s, n