|
10 | 10 | import os
|
11 | 11 |
|
12 | 12 |
|
13 |
| -phases = ['test_A'] |
| 13 | +phases = ['val'] |
14 | 14 |
|
15 | 15 | if phases[0] == 'test_A':
|
16 | 16 | test_root = 'data/test_A'
|
17 | 17 | elif phases[0] == 'test_B':
|
18 | 18 | test_root = 'data/test_B'
|
| 19 | +elif phases[0] == 'val': |
| 20 | + test_root = 'data/validation_folder' |
19 | 21 |
|
20 | 22 | label_raw = []
|
21 | 23 |
|
22 | 24 | def file_name2(file_dir): #特定类型的文件
|
23 | 25 | L=[]
|
24 | 26 | 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}) |
31 | 44 | return L, image
|
32 | 45 |
|
33 | 46 | path, image_id = file_name2(test_root) #图片目录
|
|
0 commit comments