diff --git a/.idea/ProjektAI.iml b/.idea/ProjektAI.iml index d9e6024..08884dd 100644 --- a/.idea/ProjektAI.iml +++ b/.idea/ProjektAI.iml @@ -1,8 +1,10 @@ - - + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a5061af..a7f16ed 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,8 @@ - + + + \ No newline at end of file diff --git a/kelner/images/dataset/ffries/10500.jpg b/kelner/images/dataset/ffries/10500.jpg new file mode 100644 index 0000000..9df0087 Binary files /dev/null and b/kelner/images/dataset/ffries/10500.jpg differ diff --git a/kelner/images/dataset/ffries/17394.jpg b/kelner/images/dataset/ffries/17394.jpg new file mode 100644 index 0000000..13834e8 Binary files /dev/null and b/kelner/images/dataset/ffries/17394.jpg differ diff --git a/kelner/images/dataset/ffries/20215.jpg b/kelner/images/dataset/ffries/20215.jpg new file mode 100644 index 0000000..68e0e85 Binary files /dev/null and b/kelner/images/dataset/ffries/20215.jpg differ diff --git a/kelner/images/dataset/ffries/24479.jpg b/kelner/images/dataset/ffries/24479.jpg new file mode 100644 index 0000000..a839ea7 Binary files /dev/null and b/kelner/images/dataset/ffries/24479.jpg differ diff --git a/kelner/images/dataset/ffries/43636.jpg b/kelner/images/dataset/ffries/43636.jpg new file mode 100644 index 0000000..bb8295a Binary files /dev/null and b/kelner/images/dataset/ffries/43636.jpg differ diff --git a/kelner/images/dataset/ffries/48052.jpg b/kelner/images/dataset/ffries/48052.jpg new file mode 100644 index 0000000..2726010 Binary files /dev/null and b/kelner/images/dataset/ffries/48052.jpg differ diff --git a/kelner/images/dataset/ffries/51368.jpg b/kelner/images/dataset/ffries/51368.jpg new file mode 100644 index 0000000..4ccdbd9 Binary files /dev/null and b/kelner/images/dataset/ffries/51368.jpg differ diff --git a/kelner/images/dataset/ffries/51678.jpg b/kelner/images/dataset/ffries/51678.jpg new file mode 100644 index 0000000..96b0570 Binary files /dev/null and b/kelner/images/dataset/ffries/51678.jpg differ diff --git a/kelner/images/dataset/ffries/52510.jpg b/kelner/images/dataset/ffries/52510.jpg new file mode 100644 index 0000000..4b070a2 Binary files /dev/null and b/kelner/images/dataset/ffries/52510.jpg differ diff --git a/kelner/images/dataset/ffries/57594.jpg b/kelner/images/dataset/ffries/57594.jpg new file mode 100644 index 0000000..7ab899c Binary files /dev/null and b/kelner/images/dataset/ffries/57594.jpg differ diff --git a/kelner/images/dataset/macarons/1075.jpg b/kelner/images/dataset/macarons/1075.jpg new file mode 100644 index 0000000..9654ec8 Binary files /dev/null and b/kelner/images/dataset/macarons/1075.jpg differ diff --git a/kelner/images/dataset/macarons/15110.jpg b/kelner/images/dataset/macarons/15110.jpg new file mode 100644 index 0000000..e2f6717 Binary files /dev/null and b/kelner/images/dataset/macarons/15110.jpg differ diff --git a/kelner/images/dataset/macarons/15274.jpg b/kelner/images/dataset/macarons/15274.jpg new file mode 100644 index 0000000..259750a Binary files /dev/null and b/kelner/images/dataset/macarons/15274.jpg differ diff --git a/kelner/images/dataset/macarons/17515.jpg b/kelner/images/dataset/macarons/17515.jpg new file mode 100644 index 0000000..b061f4a Binary files /dev/null and b/kelner/images/dataset/macarons/17515.jpg differ diff --git a/kelner/images/dataset/macarons/28826.jpg b/kelner/images/dataset/macarons/28826.jpg new file mode 100644 index 0000000..22a6896 Binary files /dev/null and b/kelner/images/dataset/macarons/28826.jpg differ diff --git a/kelner/images/dataset/macarons/30074.jpg b/kelner/images/dataset/macarons/30074.jpg new file mode 100644 index 0000000..3208fc9 Binary files /dev/null and b/kelner/images/dataset/macarons/30074.jpg differ diff --git a/kelner/images/dataset/macarons/305.jpg b/kelner/images/dataset/macarons/305.jpg new file mode 100644 index 0000000..c474565 Binary files /dev/null and b/kelner/images/dataset/macarons/305.jpg differ diff --git a/kelner/images/dataset/macarons/50327.jpg b/kelner/images/dataset/macarons/50327.jpg new file mode 100644 index 0000000..6727ca5 Binary files /dev/null and b/kelner/images/dataset/macarons/50327.jpg differ diff --git a/kelner/images/dataset/macarons/67737.jpg b/kelner/images/dataset/macarons/67737.jpg new file mode 100644 index 0000000..177acc6 Binary files /dev/null and b/kelner/images/dataset/macarons/67737.jpg differ diff --git a/kelner/images/dataset/macarons/70102.jpg b/kelner/images/dataset/macarons/70102.jpg new file mode 100644 index 0000000..f232d7a Binary files /dev/null and b/kelner/images/dataset/macarons/70102.jpg differ diff --git a/kelner/images/dataset/peas/11883.jpg b/kelner/images/dataset/peas/11883.jpg new file mode 100644 index 0000000..817e247 Binary files /dev/null and b/kelner/images/dataset/peas/11883.jpg differ diff --git a/kelner/images/dataset/peas/17431.jpg b/kelner/images/dataset/peas/17431.jpg new file mode 100644 index 0000000..4e3303f Binary files /dev/null and b/kelner/images/dataset/peas/17431.jpg differ diff --git a/kelner/images/dataset/peas/17923.jpg b/kelner/images/dataset/peas/17923.jpg new file mode 100644 index 0000000..279a15c Binary files /dev/null and b/kelner/images/dataset/peas/17923.jpg differ diff --git a/kelner/images/dataset/peas/17928.jpg b/kelner/images/dataset/peas/17928.jpg new file mode 100644 index 0000000..c25f3cf Binary files /dev/null and b/kelner/images/dataset/peas/17928.jpg differ diff --git a/kelner/images/dataset/peas/19123.jpg b/kelner/images/dataset/peas/19123.jpg new file mode 100644 index 0000000..1b5b27a Binary files /dev/null and b/kelner/images/dataset/peas/19123.jpg differ diff --git a/kelner/images/dataset/peas/20934.jpg b/kelner/images/dataset/peas/20934.jpg new file mode 100644 index 0000000..7517f42 Binary files /dev/null and b/kelner/images/dataset/peas/20934.jpg differ diff --git a/kelner/images/dataset/peas/42964.jpg b/kelner/images/dataset/peas/42964.jpg new file mode 100644 index 0000000..886ae72 Binary files /dev/null and b/kelner/images/dataset/peas/42964.jpg differ diff --git a/kelner/images/dataset/peas/4321.jpg b/kelner/images/dataset/peas/4321.jpg new file mode 100644 index 0000000..64e97bd Binary files /dev/null and b/kelner/images/dataset/peas/4321.jpg differ diff --git a/kelner/images/dataset/peas/5531.jpg b/kelner/images/dataset/peas/5531.jpg new file mode 100644 index 0000000..c2e8ff4 Binary files /dev/null and b/kelner/images/dataset/peas/5531.jpg differ diff --git a/kelner/images/dataset/peas/5615.jpg b/kelner/images/dataset/peas/5615.jpg new file mode 100644 index 0000000..e173525 Binary files /dev/null and b/kelner/images/dataset/peas/5615.jpg differ diff --git a/kelner/images/dataset/pizza/11297.jpg b/kelner/images/dataset/pizza/11297.jpg new file mode 100644 index 0000000..a7f4270 Binary files /dev/null and b/kelner/images/dataset/pizza/11297.jpg differ diff --git a/kelner/images/dataset/pizza/2965.jpg b/kelner/images/dataset/pizza/2965.jpg new file mode 100644 index 0000000..2945005 Binary files /dev/null and b/kelner/images/dataset/pizza/2965.jpg differ diff --git a/kelner/images/dataset/pizza/34632.jpg b/kelner/images/dataset/pizza/34632.jpg new file mode 100644 index 0000000..dd62b88 Binary files /dev/null and b/kelner/images/dataset/pizza/34632.jpg differ diff --git a/kelner/images/dataset/pizza/40449.jpg b/kelner/images/dataset/pizza/40449.jpg new file mode 100644 index 0000000..91ccbee Binary files /dev/null and b/kelner/images/dataset/pizza/40449.jpg differ diff --git a/kelner/images/dataset/pizza/53217.jpg b/kelner/images/dataset/pizza/53217.jpg new file mode 100644 index 0000000..f4cd7c6 Binary files /dev/null and b/kelner/images/dataset/pizza/53217.jpg differ diff --git a/kelner/images/dataset/pizza/54540.jpg b/kelner/images/dataset/pizza/54540.jpg new file mode 100644 index 0000000..c6eba15 Binary files /dev/null and b/kelner/images/dataset/pizza/54540.jpg differ diff --git a/kelner/images/dataset/pizza/56449.jpg b/kelner/images/dataset/pizza/56449.jpg new file mode 100644 index 0000000..363a539 Binary files /dev/null and b/kelner/images/dataset/pizza/56449.jpg differ diff --git a/kelner/images/dataset/pizza/5764.jpg b/kelner/images/dataset/pizza/5764.jpg new file mode 100644 index 0000000..a478afc Binary files /dev/null and b/kelner/images/dataset/pizza/5764.jpg differ diff --git a/kelner/images/dataset/pizza/59445.jpg b/kelner/images/dataset/pizza/59445.jpg new file mode 100644 index 0000000..3f64a1e Binary files /dev/null and b/kelner/images/dataset/pizza/59445.jpg differ diff --git a/kelner/images/dataset/pizza/8917.jpg b/kelner/images/dataset/pizza/8917.jpg new file mode 100644 index 0000000..614cd85 Binary files /dev/null and b/kelner/images/dataset/pizza/8917.jpg differ diff --git a/kelner/main.py b/kelner/main.py index 2d731eb..f4292dc 100644 --- a/kelner/main.py +++ b/kelner/main.py @@ -10,11 +10,12 @@ from kelner.src.managers.WaiterManager import WaiterManager from kelner.src.algorithms.DecisionTree import Tree_Builder from kelner.src.managers.KitchenManager import KitchenManager from kelner.src.algorithms.CNN.PrepareData import LoadModelThread +from kelner.src.algorithms.FoodNet import classify import kelner.src.settings as settings -import time +# import time # create screen consts -Scale = 2 # scale for all images used within project +Scale = 1 # scale for all images used within project CellSize = round(50 * Scale) # pixel size of 1 square cell in the grid PaintOffset = CellSize # pixel size of paint offset for all drawables GridCountX = 15 # number of columns in grid @@ -23,9 +24,14 @@ ScreenWidth = CellSize * GridCountX + 2 * PaintOffset # screen width in pixels ScreenHeight = CellSize * GridCountY + 2 * PaintOffset # screen height in pixels running_tasks = {'table': [], 'waiter': []} + + # initialize background gridBoard = GridBoard(ScreenWidth, ScreenHeight) + +classify.join('C:/Users/Maria/Desktop/ProjektAI/kelner/src/algorithms/FoodNet/classify.py') + # start loading prediction model settings.init() load_model_thread = LoadModelThread() @@ -40,7 +46,7 @@ drawableManager = DrawableCollection() # initialize menu manager menuManager = MenuManager() -##TESTING THE DECISION TREE +# TESTING THE DECISION TREE # Testing Data testing_db = [ [1, 0, 0, 0, "Kurczak"], diff --git a/kelner/src/algorithms/CNN/PrepareData.py b/kelner/src/algorithms/CNN/PrepareData.py index 763ed2b..98f6361 100644 --- a/kelner/src/algorithms/CNN/PrepareData.py +++ b/kelner/src/algorithms/CNN/PrepareData.py @@ -2,16 +2,15 @@ from collections import defaultdict from shutil import copytree, rmtree, copy import matplotlib.pyplot as plt import os -os.environ['TF_CPP_MIN_LOG_LEVEL']='2' import threading from tensorflow.keras.models import load_model import kelner.src.settings as settings # currently all images are not stored in repo because of big weight (5 GB) -data_dir = 'D:\\Nauka\\Studia\\4_sem\\SztucznaInteligencja\\A_star\\CNN\\foodRecognitionCNN\\food-101\\images' -folder_dir = 'D:\\Nauka\\Studia\\4_sem\\SztucznaInteligencja\\A_star\\CNN\\foodRecognitionCNN\\food-101' -foods_sorted = sorted(os.listdir(data_dir)) -food_id = 0 +#data_dir = 'D:\\Nauka\\Studia\\4_sem\\SztucznaInteligencja\\A_star\\CNN\\foodRecognitionCNN\\food-101\\images' +#folder_dir = 'D:\\Nauka\\Studia\\4_sem\\SztucznaInteligencja\\A_star\\CNN\\foodRecognitionCNN\\food-101' +#foods_sorted = sorted(os.listdir(data_dir)) +#food_id = 0 # VISUALIZE DATA # diff --git a/kelner/src/algorithms/FoodNet/classify.py b/kelner/src/algorithms/FoodNet/classify.py new file mode 100644 index 0000000..32a39bd --- /dev/null +++ b/kelner/src/algorithms/FoodNet/classify.py @@ -0,0 +1,99 @@ +import tensorflow as tf +from PIL import Image +import sys, numpy +from os import listdir +from os.path import isfile, join +from tensorflow import keras +import matplotlib.pyplot as plt + +MACARONS_DIR = '/kelner/images/dataset/macarons' +PIZZA_DIR = '/kelner/images/dataset/pizza' +FFRIES_DIR = '/kelner/images/dataset/ffries' +PEAS_DIR = '/kelner/src/images/dataset/peas' +COUNT = 10 +SIZE = 128, 128 + +def getFileList(folder): + return [f for f in listdir(folder) if isfile(join(folder, f))] + +def conv(arr): + res = [] + for i in arr: + res.append([j[0] for j in i]) + return numpy.array(res) + +def getArray(filename): + pic = Image.open(filename).convert('LA').resize(SIZE, Image.ANTIALIAS) + return numpy.array([conv(numpy.array(pic)) / 255.0]) + + +macaronsImages = getFileList(MACARONS_DIR) +pizzaImages = getFileList(PIZZA_DIR) +ffriesImages = getFileList(FFRIES_DIR) +peasImages = getFileList(PEAS_DIR) +train_images = [] +train_labels = [] +test_images = [] +test_labels = [] + +for i in range(COUNT): + pic = Image.open(MACARONS_DIR + '/' + macaronsImages[i]).convert('LA').resize(SIZE, Image.ANTIALIAS) + train_images.append(conv(numpy.array(pic)) / 255.0) + train_labels.append(0) + if i < COUNT / 10: + test_images.append(conv(numpy.array(pic)) / 255.0) + test_labels.append(0) + pic = Image.open(PIZZA_DIR + '/' + pizzaImages[i]).convert('LA').resize(SIZE, Image.ANTIALIAS) + train_images.append(conv(numpy.array(pic)) / 255.0) + train_labels.append(1) + if i < COUNT / 10: + test_images.append(conv(numpy.array(pic)) / 255.0) + test_labels.append(1) + pic = Image.open(FFRIES_DIR + '/' + ffriesImages[i]).convert('LA').resize(SIZE, Image.ANTIALIAS) + train_images.append(conv(numpy.array(pic)) / 255.0) + train_labels.append(2) + if i < COUNT / 10: + test_images.append(conv(numpy.array(pic)) / 255.0) + test_labels.append(2) + pic = Image.open(PEAS_DIR + '/' + peasImages[i]).convert('LA').resize(SIZE, Image.ANTIALIAS) + train_images.append(conv(numpy.array(pic)) / 255.0) + train_labels.append(3) + if i < COUNT / 10: + test_images.append(conv(numpy.array(pic)) / 255.0) + test_labels.append(3) + +train_i = numpy.array(train_images) +train_l = numpy.array(train_labels) +test_i = numpy.array(test_images) +test_l = numpy.array(test_labels) + + +class_names = ['macarons', 'pizza', 'ffries', 'peas'] + +model = keras.Sequential([ + keras.layers.Flatten(input_shape=SIZE), + keras.layers.Dense(128, activation=tf.nn.relu), + keras.layers.Dense(4, activation=tf.nn.softmax) +]) + + +model.compile(optimizer=tf.compat.v1.train.AdamOptimizer(), + loss='sparse_categorical_crossentropy', + metrics=['accuracy']) + + + +model.fit(train_i, train_l, epochs=15) + +test_loss, test_acc = model.evaluate(test_i, test_l) +print('Test accuracy:', test_acc) + +predictions = model.predict(test_i) + +if len(sys.argv) > 1: + predictions = model.predict([getArray(sys.argv[1])]) + if numpy.max(predictions) > 0.5: + print(class_names[numpy.argmax(predictions)]) + else: + print('mix') +print(numpy.max(predictions)) \ No newline at end of file