-
Notifications
You must be signed in to change notification settings - Fork 1
/
food_recognition.py
42 lines (32 loc) ยท 2.04 KB
/
food_recognition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications.inception_v3 import InceptionV3, preprocess_input
model = tf.keras.models.load_model('./food_recognition_model2.h5')
label_to_int = {'๊ฐ๋น์ฐ': 0, '๊ฐ์๋ณถ์': 1, '๊ณ ๊ตฌ๋ง': 2, '๊ณ ์ถ ์ฅ์์ฐ': 3, '๊ตญ์': 4, '๋จํธ๋ฐ์ฐ': 5, '๋ฌ๊ฑ์ฐ': 6, '๋ฌ๊ฑํ๋ผ์ด': 7, '๋ญ๊ฐ๋น': 8, '๋์ฅ๊ตญ': 9, '๋์ฅ์ฐ๊ฐ': 10, '๋ก๊ตญ': 11, '๋ง๋๊ตญ': 12, '๋ฌด๊น์น': 13, '๋ฏธ์ญ๊ตญ': 14, '๋ฏธ์ญ๋๋ฌผ': 15, '๋ฐ๋๋': 16, '๋ฐฅ': 17, '๋ฐฉ์ธํ ๋งํ ': 18, '๋ฐฐ์ถ๊น์น': 19, '๋ถ์นจ๊ฐ': 20, '๋ธ๋ก์ฝ๋ฆฌ': 21, '๋น์๋ ์์์ง': 22, '๋นต': 23, '์ฌ๊ณผ': 24, '์ถ์ ๋ฌ๊ฑ': 25, '์ผ๊ฒน์ด๊ตฌ์ด': 26, '์์ถ': 27, '์๋์์น': 28, '์์ ๊ตฌ์ด': 29, '์๋๋ถ์ฐ๊ฐ': 30, '์คํฌ๋จ๋ธ ์๊ทธ': 31, '์ผ์ฑ๋ณถ์': 32, '์๋ฐฐ์ถ์': 33, '์์์ถ์๋ฌ๋': 34, '์ด๋ฌต๊ตญ': 35, '์ค๋ฆฌ๊ตฌ์ด': 36, '์ค๋ฏ๋ ': 37, '์ค์ด': 38, '์ฐ์ ': 39, '์ก์ฑ': 40, '์กฐ๋ฏธ๊น': 41, '์ฃฝ': 42, '์ฐ๋ญ': 43, '์ฐธ์ธ': 44, '์นํจ๋๊ฒ': 45, '์ฝฉ๋๋ฌผ ๋ฌด์นจ': 46, 'ํ ๋งํ ': 47, 'ํํ๋ฆฌ์นด': 48, 'ํฌ๋': 49, 'ํด๋ฌผ๋ณถ์': 50, 'ํ์ ์ฐ์ด': 51}
def predict_food_category(image_path):
img = tf.keras.preprocessing.image.load_img(image_path, target_size=(299, 299))
img = tf.keras.preprocessing.image.img_to_array(img)
img = tf.expand_dims(img, axis=0)
img = preprocess_input(img)
prediction = model.predict(img)[0]
predicted_class_index = np.argmax(prediction)
for key, value in label_to_int.items():
if value == predicted_class_index:
return key
else:
pass
def predict_food():
image_dir = './crop/'
src = []
file_name = []
result = []
for file in os.listdir(image_dir):
src.append(image_dir + file)
file_name.append(file)
result.append(predict_food_category(image_dir + file))
for i in range(len(result)):
print(file_name[i] + " : , Predict : "+ str(result[i]))
# ์ค๋ณต๊ฐ ์ ๊ฑฐ
food_name = set(result)
return food_name