From a51f3e31dcc60c735e69b0baf3f25e6d565a8019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szuszert?= Date: Thu, 26 May 2022 16:16:16 +0200 Subject: [PATCH] =?UTF-8?q?po=20naci=C5=9Bnieciu=20"e"=20sie=C4=87=20sie?= =?UTF-8?q?=20uczy,=20po=20podje=C5=9Bciu=20do=20prawego=20g=C3=B3rnego=20?= =?UTF-8?q?odpalane=20jest=20prediction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiles.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tiles.py b/tiles.py index ecbca20..bbb5053 100644 --- a/tiles.py +++ b/tiles.py @@ -13,6 +13,7 @@ import matplotlib.pyplot as plt import os import cv2 from tqdm import tqdm +import keras from keras.models import Sequential from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Conv2D, MaxPooling2D @@ -642,8 +643,8 @@ def prepare_img(filepath): return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1) / 255 -def predict(model): - return model.predict([prepare_img('directory')]) +def predict(model,filepath): + return model.predict([prepare_img(filepath)]) def result(prediction): @@ -733,6 +734,11 @@ def main(): key = pygame.key.get_pressed() left, middle, right = pygame.mouse.get_pressed() + + if key[pygame.K_e]: + X, y = create_training_data() + model = learn_neural_network(X,y) + if middle: waiterGo(mouseToNum()) elif right: @@ -800,9 +806,12 @@ def main(): if waiter.loc == [576, 32]: if first_time: number = np.random.randint(20) - image = pygame.image.load('test/' + str(number) + '.jpg') + path = ('test/' + str(number) + '.jpg') + image = pygame.image.load(path) first_time = False display_img(display, image) + prediction = predict(model, path) + result(prediction) else: first_time = True