-
Notifications
You must be signed in to change notification settings - Fork 3
/
make_CityScapes.py
30 lines (22 loc) · 1.02 KB
/
make_CityScapes.py
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
import os
import json
from pathlib import Path
cityscapes_root = '../../datasets/cityscapes_raw'
train_odgt = Path('./data/train_cityscapes.odgt')
val_odgt = Path('./data/validation_cityscapes.odgt')
def make_CityScapes(mode, root, odgt):
mask_path = os.path.join('gtFine', mode)
mask_postfix = '_gtFine_labelIds.png'
img_path = os.path.join('leftImg8bit', mode)
categories = os.listdir(os.path.join(root, img_path))
with odgt.open(mode='w+') as fo:
for c in categories:
c_items = [name.split('_leftImg8bit.png')[0] for name in os.listdir(os.path.join(root, img_path, c))]
for it in c_items:
item = {"width": 2048, "fpath_img": os.path.join(img_path, c, it + '_leftImg8bit.png'), "height": 1024, "fpath_segm": os.path.join(mask_path, c, it + mask_postfix)}
fo.write(f'{json.dumps(item)}\n')
def main():
make_CityScapes('train', cityscapes_root, train_odgt)
make_CityScapes('val', cityscapes_root, val_odgt)
if __name__ == '__main__':
main()