MCPcopy
hub / github.com/Sentdex/pygta5 / main

Function main

original_project/3. test_model.py:122–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120print('We have loaded a previous model!!!!')
121
122def main():
123 last_time = time.time()
124 for i in list(range(4))[::-1]:
125 print(i+1)
126 time.sleep(1)
127
128 paused = False
129 mode_choice = 0
130
131 screen = grab_screen(region=(0,40,GAME_WIDTH,GAME_HEIGHT+40))
132 screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
133 prev = cv2.resize(screen, (WIDTH,HEIGHT))
134
135 t_minus = prev
136 t_now = prev
137 t_plus = prev
138
139 while(True):
140
141 if not paused:
142 screen = grab_screen(region=(0,40,GAME_WIDTH,GAME_HEIGHT+40))
143 screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
144
145 last_time = time.time()
146 screen = cv2.resize(screen, (WIDTH,HEIGHT))
147
148 delta_count_last = motion_detection(t_minus, t_now, t_plus)
149
150 t_minus = t_now
151 t_now = t_plus
152 t_plus = screen
153 t_plus = cv2.blur(t_plus,(4,4))
154
155 prediction = model.predict([screen.reshape(WIDTH,HEIGHT,3)])[0]
156 prediction = np.array(prediction) * np.array([4.5, 0.1, 0.1, 0.1, 1.8, 1.8, 0.5, 0.5, 0.2])
157
158 mode_choice = np.argmax(prediction)
159
160 if mode_choice == 0:
161 straight()
162 choice_picked = 'straight'
163
164 elif mode_choice == 1:
165 reverse()
166 choice_picked = 'reverse'
167
168 elif mode_choice == 2:
169 left()
170 choice_picked = 'left'
171 elif mode_choice == 3:
172 right()
173 choice_picked = 'right'
174 elif mode_choice == 4:
175 forward_left()
176 choice_picked = 'forward+left'
177 elif mode_choice == 5:
178 forward_right()
179 choice_picked = 'forward+right'

Callers 1

3. test_model.pyFile · 0.70

Calls 13

grab_screenFunction · 0.90
motion_detectionFunction · 0.90
key_checkFunction · 0.90
ReleaseKeyFunction · 0.90
straightFunction · 0.70
reverseFunction · 0.70
leftFunction · 0.70
rightFunction · 0.70
forward_leftFunction · 0.70
forward_rightFunction · 0.70
reverse_leftFunction · 0.70
reverse_rightFunction · 0.70

Tested by

no test coverage detected