Skip to content

Commit 2b43dde

Browse files
authored
val2json
1 parent 3cb59a4 commit 2b43dde

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

create_json.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,37 @@
1010
import os
1111

1212

13-
phases = ['test_A']
13+
phases = ['val']
1414

1515
if phases[0] == 'test_A':
1616
test_root = 'data/test_A'
1717
elif phases[0] == 'test_B':
1818
test_root = 'data/test_B'
19+
elif phases[0] == 'val':
20+
test_root = 'data/validation_folder'
1921

2022
label_raw = []
2123

2224
def file_name2(file_dir): #特定类型的文件
2325
L=[]
2426
image = []
25-
for root, dirs, files in os.walk(file_dir):
26-
for file in files:
27-
if os.path.splitext(file)[1] == '.JPG':
28-
L.append(os.path.join(root, file))
29-
image.append(file)
30-
label_raw.append({'image_id':file, 'label_id':1})
27+
if phases[0] == 'val':
28+
for dir_ in os.listdir(file_dir):
29+
if dir_.endswith('.json'):
30+
pass
31+
else:
32+
for file in os.listdir(test_root+'/'+dir_):
33+
if os.path.splitext(file)[1] in ['.jpg', '.JPG']:
34+
L.append(test_root+'/'+dir_+'/'+file)
35+
image.append(file)
36+
label_raw.append({'image_id':file, 'label_id':int(dir_)})
37+
else:
38+
for root, dirs, files in os.walk(file_dir):
39+
for file in files:
40+
if os.path.splitext(file)[1] in ['.jpg', '.JPG']:
41+
L.append(os.path.join(root, file))
42+
image.append(file)
43+
label_raw.append({'image_id':file, 'label_id':1})
3144
return L, image
3245

3346
path, image_id = file_name2(test_root) #图片目录

0 commit comments

Comments
 (0)