This commit is contained in:
Michał Szuszert 2022-05-26 21:04:01 +02:00
parent a51f3e31dc
commit 8ac677941c

View File

@ -13,7 +13,6 @@ import matplotlib.pyplot as plt
import os import os
import cv2 import cv2
from tqdm import tqdm from tqdm import tqdm
import keras
from keras.models import Sequential from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D from keras.layers import Conv2D, MaxPooling2D
@ -620,6 +619,10 @@ def learn_neural_network(X, y):
model.add(Activation('relu')) model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2))) 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(Flatten())
model.add(Dense(64)) model.add(Dense(64))
@ -631,7 +634,7 @@ def learn_neural_network(X, y):
optimizer='adam', optimizer='adam',
metrics=['accuracy']) 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 return model
@ -649,38 +652,15 @@ def predict(model,filepath):
def result(prediction): def result(prediction):
if prediction[0][0] >= 0.5: if prediction[0][0] >= 0.5:
print(prediction)
print(math.ceil(prediction[0][0])) print(math.ceil(prediction[0][0]))
print('No pepperoni') print('No pepperoni')
elif prediction[0][0] < 0.5: elif prediction[0][0] < 0.5:
print(prediction)
print(math.floor(prediction[0][0])) print(math.floor(prediction[0][0]))
print("Pepperoni") 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() map = Map()
waiter = Waiter([32, 32]) waiter = Waiter([32, 32])
@ -703,6 +683,7 @@ for table in tables:
client = Client(generate_client()) client = Client(generate_client())
neural_prediction_in = False
def main(): def main():
direction = [] direction = []
@ -810,10 +791,16 @@ def main():
image = pygame.image.load(path) image = pygame.image.load(path)
first_time = False first_time = False
display_img(display, image) display_img(display, image)
prediction = predict(model, path) if neural_prediction_in is False:
result(prediction) prediction = predict(model, path)
result(prediction)
neural_prediction_in = True
else: else:
first_time = True first_time = True
neural_prediction_in = False
pygame.display.update() pygame.display.update()