File size: 1,150 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
37
38
39
40
41
import os 
import json
import random


data = dict()
data['database'] = dict()

categories = list()


with open("K700_val.csv", 'w') as f:
    for root, dirs, files in os.walk("./validation"):
        label = root.strip().split('/')[-1]
        if files:
            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}}

print("{} validation instances".format(len(data['database'])))

with open("K700_train.csv", 'w') as f:
    for root, dirs, files in os.walk("./training"):
        label = root.strip().split('/')[-1]
        if files:
            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:
    categories = sorted(categories)
    for i, label in enumerate(categories):
        f.write("{},{}\n".format(label, i))

with open("annotation.json", 'w') as f:
    json.dump(data, f)