-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.py
39 lines (30 loc) · 1.07 KB
/
main.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
from game import *
from training_data import generate_training_data
from keras.models import Sequential
from keras.layers import Dense
display_width = 500
display_height = 500
green = (0,255,0)
red = (255,0,0)
black = (0,0,0)
white = (255,255,255)
pygame.init()
display=pygame.display.set_mode((display_width,display_height))
clock=pygame.time.Clock()
'''
LEFT -> button_direction = 0
RIGHT -> button_direction = 1
DOWN ->button_direction = 2
UP -> button_direction = 3
'''
training_data_x, training_data_y = generate_training_data(display,clock)
model = Sequential()
model.add(Dense(units=9,input_dim=7))
model.add(Dense(units=15, activation='relu'))
model.add(Dense(output_dim=3, activation = 'softmax'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
model.fit((np.array(training_data_x).reshape(-1,7)),( np.array(training_data_y).reshape(-1,3)), batch_size = 256,epochs= 3)
model.save_weights('model.h5')
model_json = model.to_json()
with open('model.json', 'w') as json_file:
json_file.write(model_json)