forked from akshaybahadur21/Autopilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadData.py
50 lines (40 loc) · 1.31 KB
/
LoadData.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
import cv2
import numpy as np
import csv
import pickle
import matplotlib.pyplot as plt
features_directory = './data/'
labels_file = './data/driving_log.csv'
def preprocess(img):
resized = cv2.resize((cv2.cvtColor(img, cv2.COLOR_RGB2HSV))[:, :, 1], (40, 40))
return resized
def data_loading(delta):
logs = []
features = []
labels = []
with open(labels_file, 'rt') as f:
reader = csv.reader(f)
for line in reader:
logs.append(line)
log_labels = logs.pop(0)
for i in range(len(logs)):
for j in range(3):
img_path = logs[i][j]
img_path = features_directory + 'IMG' + (img_path.split('IMG')[1]).strip()
img = plt.imread(img_path)
features.append(preprocess(img))
if j == 0:
labels.append(float(logs[i][3]))
elif j == 1:
labels.append(float(logs[i][3]) + delta)
else:
labels.append(float(logs[i][3]) - delta)
return features, labels
delta = 0.2
features, labels = data_loading(delta)
features = np.array(features).astype('float32')
labels = np.array(labels).astype('float32')
with open("features_40", "wb") as f:
pickle.dump(features, f, protocol=4)
with open("labels", "wb") as f:
pickle.dump(labels, f, protocol=4)