-
Notifications
You must be signed in to change notification settings - Fork 0
/
balance_data.py
48 lines (40 loc) · 1.09 KB
/
balance_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
import numpy as np
from collections import Counter
from random import shuffle
import pandas as pd
import cv2
train_data = np.load('training_data_big_city.npy')
print(len(train_data))
df = pd.DataFrame(train_data)
print(df.head())
print(Counter(df[1].apply(str)))
lefts = []
rights = []
forwards = []
shuffle(train_data)
for data in train_data:
img = data[0]
choice = data[1]
if choice == [1, 0, 0]:
lefts.append([img, choice])
elif choice == [0, 1, 0]:
forwards.append([img, choice])
elif choice == [0, 0, 1]:
rights.append([img, choice])
else:
print('no matches')
forwards = forwards[:len(lefts)][:len(rights)]
lefts = lefts[:len(forwards)]
rights = rights[:len(forwards)]
final_data = forwards + lefts + rights
shuffle(final_data)
print(len(final_data))
np.save('training_data_v2_big_city.npy', final_data)
for data in train_data:
img = data[0]
choice = data[1]
cv2.imshow('test', img)
print(choice)
if cv2.waitKey(25) & 0xFF==ord('q'):
cv2.destroyAllWindows()
break