File size: 1,089 Bytes
32b542e |
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 |
import os
import json
data = dict()
data['database'] = dict()
categories = list()
with open("K400_val.csv", 'w') as f:
for root, dirs, files in os.walk("./validation"):
label = root.strip().split('/')[-1]
if files and label not in categories:
categories.append(label)
for fi in files:
f.write("{},{}\n".format(os.path.join(root, fi), label))
data['database'][fi] = {'subset': 'validation', 'annotations': {'label': label}}
with open("K400_train.csv", 'w') as f:
for root, dirs, files in os.walk("./training"):
label = root.strip().split('/')[-1]
if files and label not in categories:
categories.append(label)
for fi in files:
f.write("{},{}\n".format(os.path.join(root, fi), label))
data['database'][fi] = {'subset': 'training', 'annotations': {'label': label}}
with open("categories.txt", 'w') as f:
for i, label in enumerate(categories):
f.write("{},{}\n".format(label, i))
with open("annotation.json", 'w') as f:
json.dump(data, f)
|