farhanalimagsi
commited on
Commit
•
83363e3
1
Parent(s):
0ebda2d
Upload 4 files
Browse files- app.py +48 -0
- class_names.txt +102 -0
- model.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
from PIL import Image
|
7 |
+
from sklearn.metrics import classification_report
|
8 |
+
|
9 |
+
|
10 |
+
st.set_option('deprecation.showfileUploaderEncoding', False)
|
11 |
+
@st.cache_resource()
|
12 |
+
def load_model():
|
13 |
+
model = tf.keras.models.load_model('model.h5')
|
14 |
+
return model
|
15 |
+
|
16 |
+
def predict_class(image, model):
|
17 |
+
image = tf.cast(image, tf.float32)
|
18 |
+
image = tf.image.resize(image, [224, 224])
|
19 |
+
image = tf.expand_dims(image, axis=0)
|
20 |
+
prediction = model.predict(image)
|
21 |
+
return prediction
|
22 |
+
|
23 |
+
model = load_model()
|
24 |
+
st.title("Food Vision Classification")
|
25 |
+
file = st.file_uploader("Upload an iamge of food", type=["jpg", "jpeg", "png"])
|
26 |
+
|
27 |
+
|
28 |
+
col1, col2 = st.columns(2)
|
29 |
+
|
30 |
+
col1.subheader("Image to be Predicted")
|
31 |
+
col2.subheader("Results")
|
32 |
+
if file is None:
|
33 |
+
st.text("Waiting for upload....")
|
34 |
+
else:
|
35 |
+
test_image = Image.open(file)
|
36 |
+
slot = st.empty()
|
37 |
+
col1.image(test_image, caption="Input Image", width=300)
|
38 |
+
slot.text('Running inference.....')
|
39 |
+
pred = tf.squeeze(predict_class(test_image, model))
|
40 |
+
class_names = pd.read_csv("class_names.txt")
|
41 |
+
class_names = np.array(class_names["labels"])
|
42 |
+
result = class_names[tf.argmax(pred)]
|
43 |
+
slot.text('Done')
|
44 |
+
output = 'The image is a ' + result
|
45 |
+
col2.success(output)
|
46 |
+
|
47 |
+
st.subheader("Metrics")
|
48 |
+
|
class_names.txt
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
labels
|
2 |
+
apple_pie
|
3 |
+
baby_back_ribs
|
4 |
+
baklava
|
5 |
+
beef_carpaccio
|
6 |
+
beef_tartare
|
7 |
+
beet_salad
|
8 |
+
beignets
|
9 |
+
bibimbap
|
10 |
+
bread_pudding
|
11 |
+
breakfast_burrito
|
12 |
+
bruschetta
|
13 |
+
caesar_salad
|
14 |
+
cannoli
|
15 |
+
caprese_salad
|
16 |
+
carrot_cake
|
17 |
+
ceviche
|
18 |
+
cheesecake
|
19 |
+
cheese_plate
|
20 |
+
chicken_curry
|
21 |
+
chicken_quesadilla
|
22 |
+
chicken_wings
|
23 |
+
chocolate_cake
|
24 |
+
chocolate_mousse
|
25 |
+
churros
|
26 |
+
clam_chowder
|
27 |
+
club_sandwich
|
28 |
+
crab_cakes
|
29 |
+
creme_brulee
|
30 |
+
croque_madame
|
31 |
+
cup_cakes
|
32 |
+
deviled_eggs
|
33 |
+
donuts
|
34 |
+
dumplings
|
35 |
+
edamame
|
36 |
+
eggs_benedict
|
37 |
+
escargots
|
38 |
+
falafel
|
39 |
+
filet_mignon
|
40 |
+
fish_and_chips
|
41 |
+
foie_gras
|
42 |
+
french_fries
|
43 |
+
french_onion_soup
|
44 |
+
french_toast
|
45 |
+
fried_calamari
|
46 |
+
fried_rice
|
47 |
+
frozen_yogurt
|
48 |
+
garlic_bread
|
49 |
+
gnocchi
|
50 |
+
greek_salad
|
51 |
+
grilled_cheese_sandwich
|
52 |
+
grilled_salmon
|
53 |
+
guacamole
|
54 |
+
gyoza
|
55 |
+
hamburger
|
56 |
+
hot_and_sour_soup
|
57 |
+
hot_dog
|
58 |
+
huevos_rancheros
|
59 |
+
hummus
|
60 |
+
ice_cream
|
61 |
+
lasagna
|
62 |
+
lobster_bisque
|
63 |
+
lobster_roll_sandwich
|
64 |
+
macaroni_and_cheese
|
65 |
+
macarons
|
66 |
+
miso_soup
|
67 |
+
mussels
|
68 |
+
nachos
|
69 |
+
omelette
|
70 |
+
onion_rings
|
71 |
+
oysters
|
72 |
+
pad_thai
|
73 |
+
paella
|
74 |
+
pancakes
|
75 |
+
panna_cotta
|
76 |
+
peking_duck
|
77 |
+
pho
|
78 |
+
pizza
|
79 |
+
pork_chop
|
80 |
+
poutine
|
81 |
+
prime_rib
|
82 |
+
pulled_pork_sandwich
|
83 |
+
ramen
|
84 |
+
ravioli
|
85 |
+
red_velvet_cake
|
86 |
+
risotto
|
87 |
+
samosa
|
88 |
+
sashimi
|
89 |
+
scallops
|
90 |
+
seaweed_salad
|
91 |
+
shrimp_and_grits
|
92 |
+
spaghetti_bolognese
|
93 |
+
spaghetti_carbonara
|
94 |
+
spring_rolls
|
95 |
+
steak
|
96 |
+
strawberry_shortcake
|
97 |
+
sushi
|
98 |
+
tacos
|
99 |
+
takoyaki
|
100 |
+
tiramisu
|
101 |
+
tuna_tartare
|
102 |
+
waffles
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2592a354016723371dc6dc97bc94909cce9f7ca3c2813f4d0154906ce765cb4d
|
3 |
+
size 17129144
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
tensorflow
|
3 |
+
numpy
|
4 |
+
pandas
|