1
0
forked from s444417/ProjektAI

Food clasification network

This commit is contained in:
Mariia Kuzmenko 2020-06-10 17:14:40 +03:00
parent 0bfeeb2486
commit a4cf816bf2
45 changed files with 120 additions and 11 deletions

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (ProjektAI)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -3,5 +3,8 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (ProjektAI)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (ProjektAI)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -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"],

View File

@ -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 #

View File

@ -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))