added image recognition

This commit is contained in:
karoel2 2020-06-15 01:16:32 +02:00
parent a0efdc2215
commit de49a9d56b
6 changed files with 67 additions and 6 deletions

Binary file not shown.

Binary file not shown.

BIN
final1 Executable file

Binary file not shown.

BIN
food_10_64x3_test.hdf5 Normal file

Binary file not shown.

1
food_10_64x3_test.txt Normal file
View File

@ -0,0 +1 @@
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9

60
main.py
View File

@ -10,8 +10,64 @@ import numpy as np
from data import *
from choice_tree import *
import tensorflow as tf
from keras import *
import h5py
pygame.init()
WIN = 0
LOSSE = 0
DEFINE = 0
IMG_SIZE = 64
COLOR_CHANNELS = 3
CATEGORIES = [
"apple_pie",
"club_sandwich",
"greek_salad",
"hamburger",
"hot_dog",
"ice_cream",
"lasagna",
"pizza",
"steak",
"waffles"
]
model = tf.keras.models.load_model('final1')
with h5py.File('food_10_64x3_test.hdf5', "r") as f:
a_group_key = list(f.keys())[0]
data = list(f[a_group_key])
# print(len(data))
data = np.array(data)
X = np.array(data).reshape(-1, 64, 64, 3)
with open('food_10_64x3_test.txt', 'r') as f:
y = f.read().split()
temp = []
for item in y:
temp.append(int(item))
# print(len(X))
# print(len(y))
menu = []
for i in range(len(X)):
menu.append([X[i], y[i]])
random.shuffle(menu)
def image_recognition():
LOSSE += 1
for _ in range(100):
photo = random.choice(menu)
prediction = model.predict(np.expand_dims(photo[0], axis=0))
max_value = prediction[0].max()
idx = np.where(prediction[0]==max_value)
if CATEGORIES[idx[0][0]] == waiter.order_list[-1]:
WIN += 1
break
print(WIN, LOSSE - WIN)
# ai settings
#S_IDLE = ("kitchen", "middle", "inplace")
#S_FIRST = ("order", "food")
@ -160,6 +216,7 @@ class Agent:
self.orders = []
self.food = False
self.goal = (0,0)
self.order_list = []
def walk(self):
if self.path:
@ -494,6 +551,8 @@ while True:
if not waiter.orders and restaurant.tiles[waiter.y][waiter.x].clientState == "order" and not waiter.path:
restaurant.tiles[waiter.y][waiter.x].clientState = "wait"
waiter.orders = (waiter.x, waiter.y)
DEFINE += 1
waiter.order_list.append(random.choice(CATEGORIES))
if (waiter.x, waiter.y) == KITCHEN:
if waiter.orders:
restaurant.kitchen.append([waiter.orders[0], waiter.orders[1], 50])
@ -501,6 +560,7 @@ while True:
elif not waiter.food:
for t in restaurant.kitchen:
if not t[2]:
image_recognition()
waiter.BFS((t[0], t[1]))
restaurant.kitchen.remove(t)
waiter.food = True