-
Notifications
You must be signed in to change notification settings - Fork 56
/
fix_dataset.py
128 lines (110 loc) · 4.52 KB
/
fix_dataset.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#########################################################################
##
## Data loader source code for TuSimple dataset
##
#########################################################################
import math
import numpy as np
import cv2
import json
import random
from copy import deepcopy
from parameters import Parameters
#########################################################################
## Data loader class
#########################################################################
class Generator(object):
################################################################################
## initialize (load data set from url)
################################################################################
def __init__(self):
self.p = Parameters()
# load annotation data (training set)
self.train_data = []
self.test_data = []
with open(self.p.train_root_url+'label_data_0313.json') as f:
while True:
line = f.readline()
if not line:
break
jsonString = json.loads(line)
self.train_data.append(jsonString)
random.shuffle(self.train_data)
with open(self.p.train_root_url+'label_data_0531.json') as f:
while True:
line = f.readline()
if not line:
break
jsonString = json.loads(line)
self.train_data.append(jsonString)
random.shuffle(self.train_data)
with open(self.p.train_root_url+'label_data_0601.json') as f:
while True:
line = f.readline()
if not line:
break
jsonString = json.loads(line)
self.train_data.append(jsonString)
random.shuffle(self.train_data)
self.size_train = len(self.train_data)
print(self.size_train)
# load annotation data (test set)
#with open(self.p.test_root_url+'test_tasks_0627.json') as f:
with open(self.p.test_root_url+'test_label.json') as f:
while True:
line = f.readline()
if not line:
break
jsonString = json.loads(line)
self.test_data.append(jsonString)
#random.shuffle(self.test_data)
self.size_test = len(self.test_data)
print(self.size_test)
def split(self):
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
for i in range(self.size_train):
if len(self.train_data[i]['lanes']) == 6:
with open("dataset/six.json", 'a') as make_file:
six += 1
json.dump(self.train_data[i], make_file, separators=(',', ': '))
make_file.write("\n")
if len(self.train_data[i]['lanes']) == 5:
with open("dataset/five.json", 'a') as make_file:
five += 1
json.dump(self.train_data[i], make_file, separators=(',', ': '))
make_file.write("\n")
if len(self.train_data[i]['lanes']) == 4:
with open("dataset/four.json", 'a') as make_file:
four += 1
json.dump(self.train_data[i], make_file, separators=(',', ': '))
make_file.write("\n")
if len(self.train_data[i]['lanes']) == 3:
with open("dataset/three.json", 'a') as make_file:
three += 1
json.dump(self.train_data[i], make_file, separators=(',', ': '))
make_file.write("\n")
if len(self.train_data[i]['lanes']) == 2:
with open("dataset/two.json", 'a') as make_file:
two += 1
json.dump(self.train_data[i], make_file, separators=(',', ': '))
make_file.write("\n")
if len(self.train_data[i]['lanes']) == 1:
with open("dataset/one.json", 'a') as make_file:
one += 1
json.dump(self.train_data[i], make_file, separators=(',', ': '))
make_file.write("\n")
print("six = " + str(six))
print("five = " + str(five))
print("four = " + str(four))
print("three = " + str(three))
print("two = " + str(two))
print("one = " + str(one))
print("total = " + str(one+two+three+four+five+six))
if __name__ == '__main__':
G = Generator()
G.split()