Individual project #1 #1

Merged
s444519 merged 1 commits from s444523/Waiter_group:master into master 2020-04-30 09:52:50 +02:00
3 changed files with 47 additions and 13 deletions

BIN
plates.rar Normal file

Binary file not shown.

BIN
s444523.rar Normal file

Binary file not shown.

View File

@ -8,10 +8,37 @@ import math
# For CNN: # For CNN:
import keras import keras
from keras.models import load_model
from keras.preprocessing import image 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 ### ### WS ###
@ -53,7 +80,10 @@ class Table:
# The finction "state of meal" chooses a photo of a plate at the given table. # The finction "state of meal" chooses a photo of a plate at the given table.
def state_of_meal(self): def state_of_meal(self):
num = np.random.randint(1, 102) ## !!!!!!###
num = np.random.randint(67, 100)
## !!!!!!###
if num<=67: if num<=67:
img_name = 'plates/{}.png'.format(num) img_name = 'plates/{}.png'.format(num)
else: else:
@ -121,15 +151,19 @@ class Agent:
def check_plates(self, table_number): def check_plates(self, table_number):
table = self.define_table(table_number) table = self.define_table(table_number)
plate = table.state_of_meal() plate = table.state_of_meal()
clean_plate = image.load_img(plate, target_size = (256, 256)) plate= image.load_img(plate, target_size = (256, 256))
clean_plate = image.img_to_array(clean_plate) plate = image.img_to_array(plate)
clean_plate = np.expand_dims(clean_plate, axis = 0) plate = np.expand_dims(plate, axis = 0)
result = saved_model.predict(clean_plate)[0] result = classifier.predict(plate)[0]
for i, x in enumerate (result): print (result)
if x: if result[1] == 1:
pred_class = i result[1] = 0
table.change_state(pred_class) 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 ### ### /WS ###
######################## ########################
@ -327,7 +361,7 @@ while not done:
# After each fool loop, we can quit the program:. # After each fool loop, we can quit the program:.
if len(destination_tables) == 0: if len(destination_tables) == 0:
play_again = 1 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: if play_again:
pygame.quit() pygame.quit()