Food clasification network

This commit is contained in:
Mariia Kuzmenko 2020-06-11 14:54:53 +03:00
parent f5e403b331
commit 0186ef8e00
49 changed files with 104 additions and 2 deletions

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8 (ProjektAI) (2)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.7 (ProjektAI)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

@ -11,6 +11,7 @@ from kelner.src.managers.TableGenerator import TableGenerator
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
Scale = 1.5 # scale for all images used within project
@ -25,6 +26,8 @@ running_tasks = {'table': [], 'waiter': []}
# initialize background
gridBoard = GridBoard(ScreenWidth, ScreenHeight)
classify.join('/src/algorithms/FoodNet/classify.py')
# start loading prediction model
settings.init()
load_model_thread = LoadModelThread()

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 = './././images/dataset/macarons'
PIZZA_DIR = './././images/dataset/pizza'
FFRIES_DIR = './././images/dataset/ffries'
PEAS_DIR = './././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))