added image recognition
This commit is contained in:
parent
a0efdc2215
commit
de49a9d56b
BIN
__pycache__/choice_tree.cpython-36.pyc
Normal file
BIN
__pycache__/choice_tree.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/data.cpython-36.pyc
Normal file
BIN
__pycache__/data.cpython-36.pyc
Normal file
Binary file not shown.
BIN
food_10_64x3_test.hdf5
Normal file
BIN
food_10_64x3_test.hdf5
Normal file
Binary file not shown.
1
food_10_64x3_test.txt
Normal file
1
food_10_64x3_test.txt
Normal 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 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8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 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 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
60
main.py
@ -10,8 +10,64 @@ import numpy as np
|
|||||||
from data import *
|
from data import *
|
||||||
from choice_tree import *
|
from choice_tree import *
|
||||||
|
|
||||||
|
import tensorflow as tf
|
||||||
|
from keras import *
|
||||||
|
import h5py
|
||||||
|
|
||||||
pygame.init()
|
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
|
# ai settings
|
||||||
#S_IDLE = ("kitchen", "middle", "inplace")
|
#S_IDLE = ("kitchen", "middle", "inplace")
|
||||||
#S_FIRST = ("order", "food")
|
#S_FIRST = ("order", "food")
|
||||||
@ -160,6 +216,7 @@ class Agent:
|
|||||||
self.orders = []
|
self.orders = []
|
||||||
self.food = False
|
self.food = False
|
||||||
self.goal = (0,0)
|
self.goal = (0,0)
|
||||||
|
self.order_list = []
|
||||||
|
|
||||||
def walk(self):
|
def walk(self):
|
||||||
if self.path:
|
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:
|
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"
|
restaurant.tiles[waiter.y][waiter.x].clientState = "wait"
|
||||||
waiter.orders = (waiter.x, waiter.y)
|
waiter.orders = (waiter.x, waiter.y)
|
||||||
|
DEFINE += 1
|
||||||
|
waiter.order_list.append(random.choice(CATEGORIES))
|
||||||
if (waiter.x, waiter.y) == KITCHEN:
|
if (waiter.x, waiter.y) == KITCHEN:
|
||||||
if waiter.orders:
|
if waiter.orders:
|
||||||
restaurant.kitchen.append([waiter.orders[0], waiter.orders[1], 50])
|
restaurant.kitchen.append([waiter.orders[0], waiter.orders[1], 50])
|
||||||
@ -501,6 +560,7 @@ while True:
|
|||||||
elif not waiter.food:
|
elif not waiter.food:
|
||||||
for t in restaurant.kitchen:
|
for t in restaurant.kitchen:
|
||||||
if not t[2]:
|
if not t[2]:
|
||||||
|
image_recognition()
|
||||||
waiter.BFS((t[0], t[1]))
|
waiter.BFS((t[0], t[1]))
|
||||||
restaurant.kitchen.remove(t)
|
restaurant.kitchen.remove(t)
|
||||||
waiter.food = True
|
waiter.food = True
|
||||||
|
Loading…
Reference in New Issue
Block a user