Individual Project #1 implementation; s444523
A Convoultional Neural Network classyfing customers plates into three categories. Documentation inside s444523.rar
This commit is contained in:
parent
08def183f7
commit
74e6baecfa
BIN
plates.rar
Normal file
BIN
plates.rar
Normal file
Binary file not shown.
BIN
s444523.rar
Normal file
BIN
s444523.rar
Normal file
Binary file not shown.
60
waiter_v3.py
60
waiter_v3.py
@ -8,10 +8,37 @@ import math
|
||||
# For CNN:
|
||||
|
||||
import keras
|
||||
from keras.models import load_model
|
||||
from keras.preprocessing import image
|
||||
from keras.models import Sequential
|
||||
from keras.layers import Convolution2D
|
||||
from keras.layers import MaxPooling2D
|
||||
from keras.layers import Flatten
|
||||
from keras.layers import Dense
|
||||
|
||||
saved_model = load_model('s444523/best_model.h5')
|
||||
|
||||
#initializing:
|
||||
classifier = Sequential()
|
||||
#Convolution:
|
||||
classifier.add(Convolution2D(32, (3, 3), input_shape =(256, 256, 3), activation = "relu"))
|
||||
#Pooling:
|
||||
classifier.add(MaxPooling2D(pool_size = (2,2)))
|
||||
|
||||
# Adding a second convolutional layer
|
||||
classifier.add(Convolution2D(32, 3, 3, activation = 'relu'))
|
||||
classifier.add(MaxPooling2D(pool_size = (2, 2)))
|
||||
|
||||
#Flattening:
|
||||
classifier.add(Flatten())
|
||||
|
||||
#Fully connected layers::
|
||||
classifier.add(Dense(units = 128, activation = "relu"))
|
||||
classifier.add(Dense(units = 3, activation = "softmax"))
|
||||
|
||||
# loading weigjts:
|
||||
classifier.load_weights('s444523/best_model_weights2.h5')
|
||||
#Making CNN:
|
||||
classifier.compile(optimizer = "adam", loss = "categorical_crossentropy", metrics = ["accuracy"])
|
||||
|
||||
|
||||
########################
|
||||
### WS ###
|
||||
@ -53,7 +80,10 @@ class Table:
|
||||
|
||||
# The finction "state of meal" chooses a photo of a plate at the given table.
|
||||
def state_of_meal(self):
|
||||
num = np.random.randint(1, 102)
|
||||
## !!!!!!###
|
||||
num = np.random.randint(67, 100)
|
||||
## !!!!!!###
|
||||
|
||||
if num<=67:
|
||||
img_name = 'plates/{}.png'.format(num)
|
||||
else:
|
||||
@ -121,15 +151,19 @@ class Agent:
|
||||
def check_plates(self, table_number):
|
||||
table = self.define_table(table_number)
|
||||
plate = table.state_of_meal()
|
||||
clean_plate = image.load_img(plate, target_size = (256, 256))
|
||||
clean_plate = image.img_to_array(clean_plate)
|
||||
clean_plate = np.expand_dims(clean_plate, axis = 0)
|
||||
result = saved_model.predict(clean_plate)[0]
|
||||
for i, x in enumerate (result):
|
||||
if x:
|
||||
pred_class = i
|
||||
table.change_state(pred_class)
|
||||
|
||||
plate= image.load_img(plate, target_size = (256, 256))
|
||||
plate = image.img_to_array(plate)
|
||||
plate = np.expand_dims(plate, axis = 0)
|
||||
result = classifier.predict(plate)[0]
|
||||
print (result)
|
||||
if result[1] == 1:
|
||||
result[1] = 0
|
||||
x = int(input("Excuse me, have You done eating? 1=Yes, 2 = No \n"))
|
||||
result[x] = 1
|
||||
for i, x in enumerate(result):
|
||||
if result[i] == 1:
|
||||
table.change_state(i)
|
||||
|
||||
########################
|
||||
### /WS ###
|
||||
########################
|
||||
@ -327,7 +361,7 @@ while not done:
|
||||
# After each fool loop, we can quit the program:.
|
||||
if len(destination_tables) == 0:
|
||||
play_again = 1
|
||||
play_again = int(input("Exit? 0=No, 1=Yes"))
|
||||
play_again = int(input("Exit? 0=No, 1=Yes \n"))
|
||||
if play_again:
|
||||
pygame.quit()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user