Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1518ee4

Browse files
authoredMay 8, 2017
Create collecting-data-for-larger-fpv-model.py
submitting a data collection file for people who wish to contribute data.
1 parent baf1d44 commit 1518ee4

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
 
+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
'''
2+
This file is meant to collect data for the latest model.
3+
4+
The data should be first person view data with the *HOOD CAMERA* in an armored Karuma.
5+
6+
I mainly train during day, but I would like more data from other times of day/weather, so feel free to submit whatever you like.
7+
8+
I will check all data for fitment to AI (basically how close does my AI predict the data you submit) to validate
9+
against people trying to submit bad data.
10+
11+
When you have some data files, host them to google docs or something of that sort and share with
12+
Harrison@pythonprogramming.net
13+
'''
14+
# create_training_data.py
15+
16+
import numpy as np
17+
from grabscreen import grab_screen
18+
import cv2
19+
import time
20+
from getkeys import key_check
21+
import os
22+
23+
24+
w = [1,0,0,0,0,0,0,0,0]
25+
s = [0,1,0,0,0,0,0,0,0]
26+
a = [0,0,1,0,0,0,0,0,0]
27+
d = [0,0,0,1,0,0,0,0,0]
28+
wa = [0,0,0,0,1,0,0,0,0]
29+
wd = [0,0,0,0,0,1,0,0,0]
30+
sa = [0,0,0,0,0,0,1,0,0]
31+
sd = [0,0,0,0,0,0,0,1,0]
32+
nk = [0,0,0,0,0,0,0,0,1]
33+
34+
def keys_to_output(keys):
35+
'''
36+
Convert keys to a ...multi-hot... array
37+
0 1 2 3 4 5 6 7 8
38+
[W, S, A, D, WA, WD, SA, SD, NOKEY] boolean values.
39+
'''
40+
output = [0,0,0,0,0,0,0,0,0]
41+
42+
43+
if 'W' in keys and 'A' in keys:
44+
output = wa
45+
elif 'W' in keys and 'D' in keys:
46+
output = wd
47+
elif 'S' in keys and 'A' in keys:
48+
output = sa
49+
elif 'S' in keys and 'D' in keys:
50+
output = sd
51+
elif 'W' in keys:
52+
output = w
53+
elif 'S' in keys:
54+
output = s
55+
elif 'A' in keys:
56+
output = a
57+
elif 'D' in keys:
58+
output = d
59+
else:
60+
output = nk
61+
return output
62+
63+
64+
file_name = 'training_data.npy'
65+
66+
if os.path.isfile(file_name):
67+
print('File exists, loading previous data!')
68+
training_data = list(np.load(file_name))
69+
else:
70+
print('File does not exist, starting fresh!')
71+
training_data = []
72+
73+
74+
def main():
75+
76+
for i in list(range(4))[::-1]:
77+
print(i+1)
78+
time.sleep(1)
79+
80+
paused = False
81+
while(True):
82+
83+
if not paused:
84+
# 800x600 windowed mode
85+
screen = grab_screen(region=(0,40,800,640))
86+
last_time = time.time()
87+
screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
88+
screen = cv2.resize(screen, (160,120))
89+
# resize to something a bit more acceptable for a CNN
90+
keys = key_check()
91+
output = keys_to_output(keys)
92+
training_data.append([screen,output])
93+
94+
if len(training_data) % 1000 == 0:
95+
print(len(training_data))
96+
np.save(file_name,training_data)
97+
98+
keys = key_check()
99+
if 'T' in keys:
100+
if paused:
101+
paused = False
102+
print('unpaused!')
103+
time.sleep(1)
104+
else:
105+
print('Pausing!')
106+
paused = True
107+
time.sleep(1)
108+
109+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.