-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcamvid.py
109 lines (94 loc) · 2.48 KB
/
camvid.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
""" camvid.py
This script is to convert CamVid dataset to tfrecord format.
"""
import os
import argparse
import numpy as np
import tensorflow as tf
from PIL import Image
from utils import make_dirs
from tfrecord import *
#class_names = np.array([
# 'sky', 'building', 'pole', 'road', 'pavement', 'tree', 'signsymbol',
# 'fence', 'car', 'pedestrian', 'bicyclist', 'unlabelled'])
class_names = np.array(['TST', 'BST', 'TB', 'ZGT'])
cmap = np.array([
[128, 128, 128],
[128, 0, 0],
[192, 192, 128],
[128, 64, 128]])
cb = np.array([
0.2595,
0.1826,
4.5640,
0.1417])
'''
cmap = np.array([
[128, 128, 128],
[128, 0, 0],
[192, 192, 128],
[128, 64, 128],
[60, 40, 222],
[128, 128, 0],
[192, 128, 128],
[64, 64, 128],
[64, 0, 128],
[64, 64, 0],
[0, 128, 192],
[0, 0, 0]])
cb = np.array([
0.2595,
0.1826,
4.5640,
0.1417,
0.5051,
0.3826,
9.6446,
1.8418,
6.6823,
6.2478,
3.0,
7.3614])
'''
label_info = {
'name': class_names,
'num_class': len(class_names),
'id': np.arange(len(class_names)),
'cmap': cmap,
'cb': cb
}
def parse(line, root):
line = line.rstrip()
line = line.replace('/SegNet/CamVid', root)
return line.split(' ')
def load_path(txt_path, root):
with open(txt_path) as f:
img_gt_pairs = [parse(line, root) for line in f.readlines()]
#print(img_gt_pairs)
return img_gt_pairs
def load_splited_path(txt_path, root):
images = []
labels = []
with open(txt_path) as f:
for line in f.readlines():
image_path, label_path = parse(line, root)
images.append(image_path)
labels.append(label_path)
return images, labels
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--outdir', type=str, default='../Dataset/IronData_Camvid',
help='Path to save tfrecord')
parser.add_argument('--indir', type=str, default='../Dataset/IronData_Camvid',
help='Dataset path.')
parser.add_argument('--target', type=str, default='train',
help='train, val, test')
args = parser.parse_args()
txt_path = os.path.join(args.indir, '{}.txt'.format(args.target))
#print(txt_path)
#print(args.indir)
pairs = load_path(txt_path, args.indir)
fname = 'irodataset-Camvid-{}.tfrecord'.format(args.target)
convert_to_tfrecord(pairs, args.outdir, fname)
if __name__ == '__main__':
main()