forked from Sentdex/pygta5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collecting-data-for-larger-fpv-model.py
117 lines (93 loc) · 3.05 KB
/
collecting-data-for-larger-fpv-model.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'''
This file is meant to collect data for the latest model.
*** DO NOT BALANCE THIS DATA ***
*** DO NOT BALANCE THIS DATA ***
*** DO NOT BALANCE THIS DATA ***
Leave the data in raw form. It must be raw so I can use it for recurrent layers/motion/optical flow...etc.
Try to keep file sizes to ~4K frames and less than 200 MB
The data should be first person view data with the *HOOD CAMERA* in an armored Karuma.
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.
I will check all data for fitment to AI (basically how close does my AI predict the data you submit) to validate
against people trying to submit bad data.
When you have some data files, host them to google docs or something of that sort and share with
'''
# create_training_data.py
import numpy as np
from grabscreen import grab_screen
import cv2
import time
from getkeys import key_check
import os
w = [1,0,0,0,0,0,0,0,0]
s = [0,1,0,0,0,0,0,0,0]
a = [0,0,1,0,0,0,0,0,0]
d = [0,0,0,1,0,0,0,0,0]
wa = [0,0,0,0,1,0,0,0,0]
wd = [0,0,0,0,0,1,0,0,0]
sa = [0,0,0,0,0,0,1,0,0]
sd = [0,0,0,0,0,0,0,1,0]
nk = [0,0,0,0,0,0,0,0,1]
def keys_to_output(keys):
'''
Convert keys to a ...multi-hot... array
0 1 2 3 4 5 6 7 8
[W, S, A, D, WA, WD, SA, SD, NOKEY] boolean values.
'''
output = [0,0,0,0,0,0,0,0,0]
if 'W' in keys and 'A' in keys:
output = wa
elif 'W' in keys and 'D' in keys:
output = wd
elif 'S' in keys and 'A' in keys:
output = sa
elif 'S' in keys and 'D' in keys:
output = sd
elif 'W' in keys:
output = w
elif 'S' in keys:
output = s
elif 'A' in keys:
output = a
elif 'D' in keys:
output = d
else:
output = nk
return output
file_name = 'training_data.npy'
if os.path.isfile(file_name):
print('File exists, loading previous data!')
training_data = list(np.load(file_name))
else:
print('File does not exist, starting fresh!')
training_data = []
def main():
for i in list(range(4))[::-1]:
print(i+1)
time.sleep(1)
paused = False
while(True):
if not paused:
# 800x600 windowed mode
screen = grab_screen(region=(0,40,800,640))
last_time = time.time()
screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
screen = cv2.resize(screen, (160,90))
# resize to something a bit more acceptable for a CNN
keys = key_check()
output = keys_to_output(keys)
training_data.append([screen,output])
if len(training_data) % 1000 == 0:
print(len(training_data))
np.save(file_name,training_data)
keys = key_check()
if 'T' in keys:
if paused:
paused = False
print('unpaused!')
time.sleep(1)
else:
print('Pausing!')
paused = True
time.sleep(1)
main()