dataset, neural network
This commit is contained in:
parent
aff02f187f
commit
7e8227ecc4
BIN
restaurant.xlsx
BIN
restaurant.xlsx
Binary file not shown.
102
tiles.py
102
tiles.py
@ -4,12 +4,20 @@ import numpy as np
|
||||
import pygame
|
||||
import pytmx
|
||||
from queue import Queue
|
||||
import math
|
||||
import pandas as pd
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
import json
|
||||
import openpyxl
|
||||
import matplotlib.pyplot as plt
|
||||
import os
|
||||
import cv2
|
||||
from tqdm import tqdm
|
||||
from keras.models import Sequential
|
||||
from keras.layers import Dense, Dropout, Activation, Flatten
|
||||
from keras.layers import Conv2D, MaxPooling2D
|
||||
import math
|
||||
|
||||
|
||||
pygame.init()
|
||||
|
||||
@ -532,8 +540,6 @@ def append_choice(ans, pre, d, df):
|
||||
n_df = pd.DataFrame(data, index=[len(df) + 1])
|
||||
append_df_to_excel(n_df, "restaurant.xlsx")
|
||||
|
||||
|
||||
|
||||
def get_pizza(number):
|
||||
with open("dishes.json") as f:
|
||||
data = json.load(f)
|
||||
@ -542,6 +548,92 @@ def get_pizza(number):
|
||||
food = Food(i['name'], i['pos_in_card'], i['price'], i['spiciness'], i['vege'], i['size'], i['allergens'], i['ingridients'], i['drink_in'])
|
||||
return food
|
||||
|
||||
#network
|
||||
def create_training_data():
|
||||
DATADIR = "Images"
|
||||
CATEGORIES = ["yes", "no"]
|
||||
IMG_SIZE = 90
|
||||
training_data = []
|
||||
for category in CATEGORIES:
|
||||
path = os.path.join(DATADIR, category)
|
||||
class_num = CATEGORIES.index(category) # 0 - pepperoni, 1 - no pepperoni
|
||||
for img in tqdm(os.listdir(path)):
|
||||
try:
|
||||
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
|
||||
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
|
||||
training_data.append([new_array, class_num])
|
||||
except Exception as e:
|
||||
pass
|
||||
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)
|
||||
|
||||
print("Training data created!")
|
||||
return X,y
|
||||
|
||||
def learn_neural_network(X,y):
|
||||
X = X/255.0
|
||||
|
||||
model = Sequential()
|
||||
|
||||
model.add(Conv2D(64, (3, 3), input_shape=X.shape[1:]))
|
||||
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))
|
||||
|
||||
model.add(Dense(1))
|
||||
model.add(Activation('sigmoid'))
|
||||
|
||||
model.compile(loss='binary_crossentropy',
|
||||
optimizer='adam',
|
||||
metrics=['accuracy'])
|
||||
|
||||
model.fit(X, y, batch_size=1, epochs=10, validation_batch_size=0.1)
|
||||
|
||||
return model
|
||||
|
||||
def prepare_img(filepath):
|
||||
IMG_SIZE = 90
|
||||
img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
|
||||
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
|
||||
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1) / 255
|
||||
|
||||
def predict(model):
|
||||
return model.predict([prepare_img('directory')])
|
||||
|
||||
def reusult(prediction):
|
||||
if prediction[0][0] >= 0.5:
|
||||
print(math.ceil(prediction[0][0]))
|
||||
print('No pepperoni')
|
||||
elif prediction[0][0] < 0.5:
|
||||
print(math.floor(prediction[0][0]))
|
||||
print("Pepperoni")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
map = Map()
|
||||
waiter = Waiter([32, 32])
|
||||
|
||||
@ -591,7 +683,7 @@ def main():
|
||||
chair.render(display)
|
||||
key = pygame.key.get_pressed()
|
||||
left, middle, right = pygame.mouse.get_pressed()
|
||||
if left:
|
||||
if middle:
|
||||
waiterGo(mouseToNum())
|
||||
elif right:
|
||||
while True:
|
||||
@ -604,7 +696,7 @@ def main():
|
||||
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
|
||||
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
|
||||
break
|
||||
elif middle:
|
||||
elif left:
|
||||
if client.loc[0] in [64, 128, 192, 256, 352, 416, 480, 544]:
|
||||
while True:
|
||||
x = client.loc[1] - 32
|
||||
|
Loading…
Reference in New Issue
Block a user