File size: 897 Bytes
0c1807e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from copy import deepcopy


isp_json = []
path = './Examples'
for img_dir in sorted(os.listdir(path)):
    if os.path.isdir(os.path.join(path, img_dir)):
        ISPP = os.path.join(path, img_dir, 'ISPP')
        
        ispp = {}
        ispp['Example_id'] = img_dir
        ispp['ISPP'] = []
        img_list = []
        for idx, img in enumerate(sorted(os.listdir(ISPP))):
            ispp['ISPP'].append([os.path.join(ISPP, img), idx / 10 if '1' in img_dir else 1 - idx / 10])
        
        for file in os.listdir(os.path.join(path, img_dir)):
            if os.path.isfile(os.path.join(path, img_dir, file)):
                img_list.append(file)
                ispp['Image'] = [os.path.join(path, img_dir, file), 7]
        ispp['Remark'] = []
        isp_json.append(deepcopy(ispp))

with open('example2.json', 'w') as f:
    import json
    json.dump(isp_json, f, indent=4)