-
Notifications
You must be signed in to change notification settings - Fork 11
/
driving_data.py
99 lines (85 loc) · 3.51 KB
/
driving_data.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
import scipy.misc
import random
import numpy as np
xs = []
ys = []
accels = []
brake = []
# gear = []
opticalFlow = []
#points to the end of the last batch
train_batch_pointer = 0
val_batch_pointer = 0
corr_train_batch_pointer = 0
corr_val_batch_pointer = 0
dataPath = "indian_dataset/"
corrDataPath = "indian_dataset/corr/"
fileNamePrefix = "circuit2_x264.mp4 "
#read data.txt
with open(dataPath+"data.txt") as f:
# with open("driving_dataset/data.txt") as f:
for line in f:
# xs.append("driving_dataset/" + line.split()[0])
xs.append(dataPath + fileNamePrefix + str(int(line.split()[0])).zfill(5)+".jpg")
#the paper by Nvidia uses the inverse of the turning radius,
#but steering wheel angle is proportional to the inverse of turning radius
#so the steering wheel angle in radians is used as the output
ys.append(float(line.split()[1]) * scipy.pi / 180)
accels.append(float(line.split()[2])* scipy.pi / 180)
brake.append(float(line.split()[3]) *scipy.pi / 180)
# gear.append(float(line.split()[4]) *scipy.pi / 180)
with open(corrDataPath+"optFlow.txt") as f:
# with open("driving_dataset/data.txt") as f:
for line in f:
# xs.append("driving_dataset/" + line.split()[0])
opticalFlow.append(float(line.split()[0]) * scipy.pi / 180)
#get number of images
num_images = len(xs)
# #shuffle list of images
# c = list(zip(xs, ys))
# random.shuffle(c)
# xs, ys = zip(*c)
train_xs = xs[:int(len(xs) * 0.8)]
train_ys = ys[:int(len(xs) * 0.8)]
train_accels = accels[:int(len(xs) * 0.8)]
train_brake = brake[:int(len(xs) * 0.8)]
train_optFlow = opticalFlow[:int(len(opticalFlow) * 0.8)]
val_xs = xs[-int(len(xs) * 0.2):]
val_ys = ys[-int(len(xs) * 0.2):]
val_accels = accels[-int(len(xs) * 0.2):]
val_brake = brake[-int(len(xs) * 0.2):]
val_optFlow = opticalFlow[-int(len(opticalFlow) * 0.2):]
num_train_images = len(train_xs)
num_val_images = len(val_xs)
def LoadTrainBatch(batch_size, steer):
global train_batch_pointer
x_out = []
y_out = []
accels_out = []
brake_out = []
for i in range(0, batch_size):
if (steer):
x_out.append(scipy.misc.imresize(scipy.misc.imread(train_xs[(train_batch_pointer + i) % num_train_images])[-150:], [66,200]) / 255.0)
else:
x_out.append(scipy.misc.imresize(scipy.misc.imread(train_xs[(train_batch_pointer + i) % num_train_images])[-150:], [112, 112]) / 255.0)
y_out.append([train_ys[(train_batch_pointer + i) % num_train_images]])
accels_out.append([train_accels[(train_batch_pointer + i) % num_train_images]])
brake_out.append([train_brake[(train_batch_pointer + i) % num_train_images]])
train_batch_pointer += batch_size
return x_out, y_out, accels_out, brake_out
def LoadValBatch(batch_size, steer):
global val_batch_pointer
x_out = []
y_out = []
accels_out = []
brake_out = []
for i in range(0, batch_size):
if (steer):
x_out.append(scipy.misc.imresize(scipy.misc.imread(val_xs[(val_batch_pointer + i) % num_val_images])[-150:], [66,200]) / 255.0)
else:
x_out.append(scipy.misc.imresize(scipy.misc.imread(val_xs[(val_batch_pointer + i) % num_val_images])[-150:], [112, 112]) / 255.0)
y_out.append([val_ys[(val_batch_pointer + i) % num_val_images]])
accels_out.append([val_accels[(val_batch_pointer + i) % num_val_images]])
brake_out.append([val_brake[(val_batch_pointer + i) % num_val_images]])
val_batch_pointer += batch_size
return x_out, y_out, accels_out, brake_out