Spaces:
Runtime error
Runtime error
Commit
·
64c2f0e
1
Parent(s):
d58bcfb
Upload 14 files
Browse files- .gitattributes +1 -0
- 101_food_class_100_percent_saved_big_model/keras_metadata.pb +3 -0
- 101_food_class_100_percent_saved_big_model/saved_model.pb +3 -0
- 101_food_class_100_percent_saved_big_model/variables/variables.data-00000-of-00001 +3 -0
- 101_food_class_100_percent_saved_big_model/variables/variables.index +0 -0
- app.py +104 -0
- requirements.txt +4 -0
- test_images/Cardamom-Saffron-Cupcakes-1.jpg +0 -0
- test_images/Punjabi-Samosa-2.jpg +0 -0
- test_images/doughnut_1.jpg +0 -0
- test_images/dumpling.jpg +0 -0
- test_images/frenchfries.jpg +0 -0
- test_images/pancake.jpg +0 -0
- test_images/pizza_1.jpg +0 -0
- test_images/waffle.jpg +0 -0
.gitattributes
CHANGED
|
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
101_food_class_100_percent_saved_big_model/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
101_food_class_100_percent_saved_big_model/keras_metadata.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fa4004d0d4bbdfd447f39866ffc135b60a6753d5feeed9cdec612ff6b7f2125
|
| 3 |
+
size 772844
|
101_food_class_100_percent_saved_big_model/saved_model.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8f56a7ef6c9e44334287d49fc6659778101a3251e30a7aa867f740fabf3c65e9
|
| 3 |
+
size 5951086
|
101_food_class_100_percent_saved_big_model/variables/variables.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e297ea1a0347b28c514af39144a31d64c1abb4f40e2a6f3447702573f1c912b
|
| 3 |
+
size 16922493
|
101_food_class_100_percent_saved_big_model/variables/variables.index
ADDED
|
Binary file (18.6 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import streamlit as st
|
| 3 |
+
# import cv2
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from streamlit_image_select import image_select
|
| 6 |
+
# import os
|
| 7 |
+
|
| 8 |
+
def load_and_prep_image(filename, img_shape=224, scale=True):
|
| 9 |
+
"""
|
| 10 |
+
Reads in an image from filename, turns it into a tensor and reshapes into
|
| 11 |
+
(224, 224, 3).
|
| 12 |
+
|
| 13 |
+
Parameters
|
| 14 |
+
----------
|
| 15 |
+
filename (str): string filename of target image
|
| 16 |
+
img_shape (int): size to resize target image to, default 224
|
| 17 |
+
scale (bool): whether to scale pixel values to range(0, 1), default True
|
| 18 |
+
"""
|
| 19 |
+
# # Read in the image
|
| 20 |
+
# img = tf.io.read_file(filename)
|
| 21 |
+
# # Decode it into a tensor
|
| 22 |
+
# img = tf.io.decode_image(img)
|
| 23 |
+
img = tf.convert_to_tensor(filename)
|
| 24 |
+
# Resize the image
|
| 25 |
+
img = tf.image.resize(img, [img_shape, img_shape])
|
| 26 |
+
if scale:
|
| 27 |
+
# Rescale the image (get all values between 0 and 1)
|
| 28 |
+
return img/255.
|
| 29 |
+
else:
|
| 30 |
+
return img
|
| 31 |
+
|
| 32 |
+
class_names = ['apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets',
|
| 33 |
+
'bibimbap', 'bread_pudding', 'breakfast_burrito', 'bruschetta', 'caesar_salad', 'cannoli', 'caprese_salad', 'carrot_cake',
|
| 34 |
+
'ceviche', 'cheese_plate', 'cheesecake', 'chicken_curry', 'chicken_quesadilla', 'chicken_wings', 'chocolate_cake',
|
| 35 |
+
'chocolate_mousse', 'churros', 'clam_chowder', 'club_sandwich', 'crab_cakes', 'creme_brulee', 'croque_madame',
|
| 36 |
+
'cup_cakes', 'deviled_eggs', 'donuts', 'dumplings', 'edamame', 'eggs_benedict', 'escargots', 'falafel', 'filet_mignon',
|
| 37 |
+
'fish_and_chips', 'foie_gras', 'french_fries', 'french_onion_soup', 'french_toast', 'fried_calamari', 'fried_rice',
|
| 38 |
+
'frozen_yogurt', 'garlic_bread', 'gnocchi', 'greek_salad', 'grilled_cheese_sandwich', 'grilled_salmon', 'guacamole',
|
| 39 |
+
'gyoza', 'hamburger', 'hot_and_sour_soup', 'hot_dog', 'huevos_rancheros', 'hummus', 'ice_cream', 'lasagna', 'lobster_bisque',
|
| 40 |
+
'lobster_roll_sandwich', 'macaroni_and_cheese', 'macarons', 'miso_soup', 'mussels', 'nachos', 'omelette', 'onion_rings',
|
| 41 |
+
'oysters', 'pad_thai', 'paella', 'pancakes', 'panna_cotta', 'peking_duck', 'pho', 'pizza', 'pork_chop', 'poutine', 'prime_rib',
|
| 42 |
+
'pulled_pork_sandwich', 'ramen', 'ravioli', 'red_velvet_cake', 'risotto', 'samosa', 'sashimi', 'scallops', 'seaweed_salad',
|
| 43 |
+
'shrimp_and_grits', 'spaghetti_bolognese', 'spaghetti_carbonara', 'spring_rolls', 'steak', 'strawberry_shortcake', 'sushi',
|
| 44 |
+
'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles']
|
| 45 |
+
|
| 46 |
+
#load model
|
| 47 |
+
@st.cache(allow_output_mutation = True)
|
| 48 |
+
def cache_model(model_name):
|
| 49 |
+
model = tf.keras.models.load_model(model_name)
|
| 50 |
+
return (model)
|
| 51 |
+
model = cache_model("101_food_class_100_percent_saved_big_model")
|
| 52 |
+
# model = tf.keras.models.load_model("101_food_class_100_percent_saved_big_model")
|
| 53 |
+
|
| 54 |
+
st.write("""
|
| 55 |
+
# Food Classification App
|
| 56 |
+
"""
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
st.write("""#### ***Upload food image and this app will classify the uploaded image from one of the mentioned categories.***""")
|
| 60 |
+
|
| 61 |
+
st.write("""
|
| 62 |
+
**Some major food categories**
|
| 63 |
+
```
|
| 64 |
+
pizza, cup_cakes, donuts, samosa, ice_cream, french_fries, waffles etc.
|
| 65 |
+
```
|
| 66 |
+
for full categories list please visit the [link](https://github.com/gourav300/food_app)
|
| 67 |
+
""")
|
| 68 |
+
|
| 69 |
+
### load file
|
| 70 |
+
uploaded_file = st.file_uploader("Upload an image file for above mentioned Food Categories or select a food image", type=["jpg", "png", "jpeg"])
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
test_img = image_select(
|
| 74 |
+
label="Select a sample food image",
|
| 75 |
+
images=[
|
| 76 |
+
"test_images/Cardamom-Saffron-Cupcakes-1.jpg",
|
| 77 |
+
"test_images/doughnut_1.jpg",
|
| 78 |
+
"test_images/frenchfries.jpg",
|
| 79 |
+
"test_images/Punjabi-Samosa-2.jpg",
|
| 80 |
+
"test_images/dumpling.jpg",
|
| 81 |
+
"test_images/pizza_1.jpg",
|
| 82 |
+
"test_images/waffle.jpg",
|
| 83 |
+
"test_images/pancake.jpg"
|
| 84 |
+
],
|
| 85 |
+
captions=["Cupcake", "Doughnut", "French fries", "Samosa", "Dumpling", "Pizza", "Waffle", "Pancake"],
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
# st.set_option('deprecation.showfileUploaderEncoding', False)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if uploaded_file is not None:
|
| 92 |
+
|
| 93 |
+
image = Image.open(uploaded_file)
|
| 94 |
+
st.image(image,width = 500)#, use_column_width=True)
|
| 95 |
+
else:
|
| 96 |
+
image = Image.open(test_img)
|
| 97 |
+
st.image(image, width = 500)#,use_column_width=True)
|
| 98 |
+
|
| 99 |
+
# Load the image and make predictions
|
| 100 |
+
img = load_and_prep_image(image, scale=False) # don't scale images for EfficientNet predictions
|
| 101 |
+
pred_prob = model.predict(tf.expand_dims(img, axis=0)) # model accepts tensors of shape [None, 224, 224, 3]
|
| 102 |
+
pred_class = class_names[pred_prob.argmax()] # find the predicted class
|
| 103 |
+
|
| 104 |
+
st.write(f"## Predicted food: {pred_class}, with Probability: {pred_prob.max():.2f}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow == 2.11.0
|
| 2 |
+
streamlit == 1.15.2
|
| 3 |
+
Pillow == 9.3.0
|
| 4 |
+
streamlit-image-select == 0.5.1
|
test_images/Cardamom-Saffron-Cupcakes-1.jpg
ADDED
|
test_images/Punjabi-Samosa-2.jpg
ADDED
|
test_images/doughnut_1.jpg
ADDED
|
test_images/dumpling.jpg
ADDED
|
test_images/frenchfries.jpg
ADDED
|
test_images/pancake.jpg
ADDED
|
test_images/pizza_1.jpg
ADDED
|
test_images/waffle.jpg
ADDED
|