import os | |
import scipy.io | |
mat = scipy.io.loadmat('meta.mat') | |
classes = os.listdir("./train") | |
classes = sorted(classes) | |
classname2idx = {} | |
idx = 0 | |
for classname in classes: | |
classname2idx[classname] = idx | |
idx += 1 | |
with open("id2wnid&class.txt", "a+") as fp: | |
for meta in mat["synsets"][:1000]: | |
meta = meta[0] | |
id, wnid = meta[0], meta[1] | |
fp.write(f"{id[0,0]},{wnid[0]},{classname2idx[wnid[0]]}\n") | |