-
Notifications
You must be signed in to change notification settings - Fork 0
/
processData.py
75 lines (62 loc) · 1.45 KB
/
processData.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
import numpy as np
import pandas as pd
import cv2
from collections import Counter
from random import shuffle
import time
import os
os.system("cls")
VISUALIZE = False or True
VISUALIZE_OUTPUT = True
train_data = np.load('train_data.npy')
print("loading train_data.npy")
df = pd.DataFrame(train_data)
print(df.head())
print(Counter(df[1].apply(str)))
if VISUALIZE:
for i in range(len(df)):
try:
z = df[0][i]
z = cv2.resize(z,(320,240),1)
cv2.imshow("train_data",z)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
time.sleep(0.01)
except:
pass
left = []
right = []
fwd = []
shuffle(train_data)
for data in train_data:
i = data[0]
label = data[1]
if label == [1,0,0]:
fwd.append([i,label])
elif label == [0,1,0]:
left.append([i,label])
elif label == [0,0,1]:
right.append([i,label])
MIN = min(len(left),len(right))
MIN = min(MIN,len(fwd))
print("MIN = %d" % MIN)
left = left[:MIN]
right = right[:MIN]
fwd = fwd[:MIN]
final_train_data = left + right + fwd
shuffle(final_train_data)
np.save('final_train_data.npy',final_train_data)
if VISUALIZE_OUTPUT:
df = pd.DataFrame(final_train_data)
for i in range(len(final_train_data)):
try:
z = df[0][i]
z = cv2.resize(z,(320,240),1)
cv2.imshow("final_train_data",z)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
time.sleep(0.01)
except:
pass