Exemplo n.º 1
0
from keras.layers import Dense

display_width = 500
display_height = 500
green = (0, 255, 0)
black = (0, 0, 0)
red = (255, 0, 0)
white = (255, 255, 255)

pygame.init()
display = pygame.display.set_mode((display_width, display_height))
clock = pygame.time.Clock()

#Left is 0, right is 1, down is 2, up is 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(activation="softmax", units=3))

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=10)
Exemplo n.º 2
0
from keras.models import Sequential
from training_data import generate_training_data
import numpy
from keras.utils import *
from keras.layers import Dense
numpy.set_printoptions(threshold=numpy.nan)

model = Sequential()

#make model with two hidden layers of 21 neurons and a single output neuron
model.add(Dense(units=7, activation='relu', input_dim=7))
model.add(Dense(units=7, activation='relu'))
model.add(Dense(units=7, activation='sigmoid'))
model.add(Dense(units=7, activation='relu'))
model.add(Dense(units=1, activation='sigmoid'))

x_train, y_train = generate_training_data()

model.compile(loss='mean_squared_error', optimizer='rmsprop', metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5, batch_size=10)

print model.predict_classes(numpy.array([[0.0,0.0,1.0,1.0,1.0,0.0,0.0]]))