vashu2425 commited on
Commit
797d27f
·
verified ·
1 Parent(s): 2ff4270

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +73 -0
  3. final_model.keras +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ final_model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ import numpy as np
5
+ import os
6
+
7
+ # Load the model
8
+ MODEL_PATH = "/home/petpooja-504/Desktop/cnn/final_model.keras"
9
+ model = tf.keras.models.load_model(MODEL_PATH)
10
+
11
+ # Define the class names directly for the Food-101 dataset
12
+ CLASS_NAMES = [
13
+ 'apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets',
14
+ 'bibimbap', 'bread_pudding', 'breakfast_burrito', 'bruschetta', 'caesar_salad', 'cannoli', 'caprese_salad',
15
+ 'carrot_cake', 'ceviche', 'cheese_plate', 'cheesecake', 'chicken_curry', 'chicken_quesadilla',
16
+ 'chicken_wings', 'chocolate_cake', 'chocolate_mousse', 'churros', 'clam_chowder', 'club_sandwich',
17
+ 'crab_cakes', 'creme_brulee', 'croque_madame', 'cup_cakes', 'deviled_eggs', 'donuts', 'dumplings',
18
+ 'edamame', 'eggs_benedict', 'escargots', 'falafel', 'filet_mignon', 'fish_and_chips', 'foie_gras',
19
+ 'french_fries', 'french_onion_soup', 'french_toast', 'fried_calamari', 'fried_rice', 'frozen_yogurt',
20
+ 'garlic_bread', 'gnocchi', 'greek_salad', 'grilled_cheese_sandwich', 'grilled_salmon', 'guacamole',
21
+ 'gyoza', 'hamburger', 'hot_and_sour_soup', 'hot_dog', 'huevos_rancheros', 'hummus', 'ice_cream',
22
+ 'lasagna', 'lobster_bisque', 'lobster_roll_sandwich', 'macaroni_and_cheese', 'macarons', 'miso_soup',
23
+ 'mussels', 'nachos', 'omelette', 'onion_rings', 'oysters', 'pad_thai', 'paella', 'pancakes', 'panna_cotta',
24
+ 'peking_duck', 'pho', 'pizza', 'pork_chop', 'poutine', 'prime_rib', 'pulled_pork_sandwich', 'ramen',
25
+ 'ravioli', 'red_velvet_cake', 'risotto', 'samosa', 'sashimi', 'scallops', 'seaweed_salad', 'shrimp_and_grits',
26
+ 'spaghetti_bolognese', 'spaghetti_carbonara', 'spring_rolls', 'steak', 'strawberry_shortcake', 'sushi',
27
+ 'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles'
28
+ ]
29
+
30
+
31
+
32
+ # Define the function to predict the image
33
+ # Define the function to predict the image
34
+ def predict_image(img_path):
35
+ # Load and preprocess the image
36
+ img = image.load_img(img_path, target_size=(224, 224)) # Resize to match model's expected input size
37
+ img_array = image.img_to_array(img) # Convert image to array
38
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
39
+ img_array = img_array / 255.0 # Normalize the image as done during training
40
+
41
+ # Make prediction
42
+ predictions = model.predict(img_array)
43
+
44
+ # Get prediction probabilities
45
+ prediction_probs = predictions[0] # Prediction probabilities
46
+ predicted_class_index = np.argmax(prediction_probs)
47
+ predicted_class = CLASS_NAMES[predicted_class_index] # Fetch the class name
48
+
49
+ return predicted_class
50
+
51
+
52
+
53
+ # Streamlit UI components
54
+ st.title("Food-101 Classification Model")
55
+ st.write("Upload an image of food to predict its class.")
56
+
57
+ # Upload image
58
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
59
+
60
+ if uploaded_file is not None:
61
+ # Display the uploaded image
62
+ st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
63
+
64
+ # Save the image temporarily
65
+ img_path = "uploaded_image.jpg"
66
+ with open(img_path, "wb") as f:
67
+ f.write(uploaded_file.getbuffer())
68
+
69
+ # Make prediction
70
+ predicted_class = predict_image(img_path)
71
+
72
+ # Display the predicted class
73
+ st.write(f"Predicted Class: {predicted_class}")
final_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c918e0962bfa2d1399c493b089924bbbd44ab9b11147e4e03a3947d625d00d1d
3
+ size 296632716