From 8ac677941cdc7c8ddf17bba43190335dc4af2fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szuszert?= Date: Thu, 26 May 2022 21:04:01 +0200 Subject: [PATCH] neural --- tiles.py | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/tiles.py b/tiles.py index bbb5053..ff730ed 100644 --- a/tiles.py +++ b/tiles.py @@ -13,7 +13,6 @@ 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 @@ -620,6 +619,10 @@ def learn_neural_network(X, y): model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) + model.add(Conv2D(64, (3, 3))) + model.add(Activation('relu')) + model.add(MaxPooling2D(pool_size=(2, 2))) + model.add(Flatten()) model.add(Dense(64)) @@ -631,7 +634,7 @@ def learn_neural_network(X, y): optimizer='adam', metrics=['accuracy']) - model.fit(X, y, batch_size=1, epochs=10, validation_batch_size=0.1) + model.fit(X, y, batch_size=32, epochs=10, validation_batch_size=0.1) return model @@ -649,38 +652,15 @@ def predict(model,filepath): def result(prediction): if prediction[0][0] >= 0.5: + print(prediction) print(math.ceil(prediction[0][0])) print('No pepperoni') elif prediction[0][0] < 0.5: + print(prediction) print(math.floor(prediction[0][0])) print("Pepperoni") -#####################neural network############################## - -DATADIR = "C:/Datasets/Ingridients" -CATEGORIES = ["yes", "no"] -IMG_SIZE = 90 -training_data = [] - -create_training_data() -X = [] -y = [] - -for features, label in training_data: - X.append(features) - y.append(label) -X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1) -y = np.array(y) -""" -m = learn_neural_network(X, y) -prediction = m.predict([prepare_img('p1.jpg')]) -print(prediction[0][0]) -result(prediction) -""" - -####################################################### - map = Map() waiter = Waiter([32, 32]) @@ -703,6 +683,7 @@ for table in tables: client = Client(generate_client()) +neural_prediction_in = False def main(): direction = [] @@ -810,10 +791,16 @@ def main(): image = pygame.image.load(path) first_time = False display_img(display, image) - prediction = predict(model, path) - result(prediction) + if neural_prediction_in is False: + prediction = predict(model, path) + result(prediction) + neural_prediction_in = True + else: first_time = True + neural_prediction_in = False + + pygame.display.update()