-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbalance_data.py
47 lines (36 loc) · 1.02 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
# balance_data.py
import numpy as np
import pandas as pd
from collections import Counter
from random import shuffle
import cv2
np_load_old = np.load
# modify the default parameters of np.load
np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)
train_data = np.load('training_data.npy')
np.load = np_load_old
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.npy', final_data)