imagenet / read_meta.py
jiachenlei's picture
Add files using upload-large-folder tool
8136987 verified
raw
history blame
433 Bytes
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")