prithivMLmods commited on
Commit
b3a85a1
·
verified ·
1 Parent(s): c44fc50

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -1
README.md CHANGED
@@ -16,6 +16,10 @@ tags:
16
  - biology
17
  ---
18
 
 
 
 
 
19
  ```py
20
  Classification Report:
21
  precision recall f1-score support
@@ -125,4 +129,91 @@ grilled_cheese_sandwich 0.8523 0.8773 0.8647 750
125
  accuracy 0.8973 75750
126
  macro avg 0.8987 0.8973 0.8977 75750
127
  weighted avg 0.8987 0.8973 0.8977 75750
128
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  - biology
17
  ---
18
 
19
+ # **Food-101-93M**
20
+
21
+ > **Food-101-93M** is a fine-tuned image classification model built on top of **google/siglip2-base-patch16-224** using the **SiglipForImageClassification** architecture. It is trained to classify food images into one of 101 popular dishes, derived from the [Food-101 dataset](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/).
22
+
23
  ```py
24
  Classification Report:
25
  precision recall f1-score support
 
129
  accuracy 0.8973 75750
130
  macro avg 0.8987 0.8973 0.8977 75750
131
  weighted avg 0.8987 0.8973 0.8977 75750
132
+ ```
133
+
134
+ The model categorizes images into 101 food classes such as `sushi`, `hamburger`, `waffles`, `pad_thai`, and more.
135
+
136
+ ---
137
+
138
+ # **Run with Transformers 🤗**
139
+
140
+ ```python
141
+ !pip install -q transformers torch pillow gradio
142
+ ```
143
+
144
+ ```python
145
+ import gradio as gr
146
+ from transformers import AutoImageProcessor, SiglipForImageClassification
147
+ from PIL import Image
148
+ import torch
149
+
150
+ # Load model and processor
151
+ model_name = "prithivMLmods/Food-101-93M"
152
+ model = SiglipForImageClassification.from_pretrained(model_name)
153
+ processor = AutoImageProcessor.from_pretrained(model_name)
154
+
155
+ # Food-101 labels
156
+ labels = {
157
+ "0": "apple_pie", "1": "baby_back_ribs", "2": "baklava", "3": "beef_carpaccio", "4": "beef_tartare",
158
+ "5": "beet_salad", "6": "beignets", "7": "bibimbap", "8": "bread_pudding", "9": "breakfast_burrito",
159
+ "10": "bruschetta", "11": "caesar_salad", "12": "cannoli", "13": "caprese_salad", "14": "carrot_cake",
160
+ "15": "ceviche", "16": "cheesecake", "17": "cheese_plate", "18": "chicken_curry", "19": "chicken_quesadilla",
161
+ "20": "chicken_wings", "21": "chocolate_cake", "22": "chocolate_mousse", "23": "churros", "24": "clam_chowder",
162
+ "25": "club_sandwich", "26": "crab_cakes", "27": "creme_brulee", "28": "croque_madame", "29": "cup_cakes",
163
+ "30": "deviled_eggs", "31": "donuts", "32": "dumplings", "33": "edamame", "34": "eggs_benedict",
164
+ "35": "escargots", "36": "falafel", "37": "filet_mignon", "38": "fish_and_chips", "39": "foie_gras",
165
+ "40": "french_fries", "41": "french_onion_soup", "42": "french_toast", "43": "fried_calamari", "44": "fried_rice",
166
+ "45": "frozen_yogurt", "46": "garlic_bread", "47": "gnocchi", "48": "greek_salad", "49": "grilled_cheese_sandwich",
167
+ "50": "grilled_salmon", "51": "guacamole", "52": "gyoza", "53": "hamburger", "54": "hot_and_sour_soup",
168
+ "55": "hot_dog", "56": "huevos_rancheros", "57": "hummus", "58": "ice_cream", "59": "lasagna",
169
+ "60": "lobster_bisque", "61": "lobster_roll_sandwich", "62": "macaroni_and_cheese", "63": "macarons", "64": "miso_soup",
170
+ "65": "mussels", "66": "nachos", "67": "omelette", "68": "onion_rings", "69": "oysters",
171
+ "70": "pad_thai", "71": "paella", "72": "pancakes", "73": "panna_cotta", "74": "peking_duck",
172
+ "75": "pho", "76": "pizza", "77": "pork_chop", "78": "poutine", "79": "prime_rib",
173
+ "80": "pulled_pork_sandwich", "81": "ramen", "82": "ravioli", "83": "red_velvet_cake", "84": "risotto",
174
+ "85": "samosa", "86": "sashimi", "87": "scallops", "88": "seaweed_salad", "89": "shrimp_and_grits",
175
+ "90": "spaghetti_bolognese", "91": "spaghetti_carbonara", "92": "spring_rolls", "93": "steak", "94": "strawberry_shortcake",
176
+ "95": "sushi", "96": "tacos", "97": "takoyaki", "98": "tiramisu", "99": "tuna_tartare", "100": "waffles"
177
+ }
178
+
179
+ def classify_food(image):
180
+ """Predicts the type of food in the image."""
181
+ image = Image.fromarray(image).convert("RGB")
182
+ inputs = processor(images=image, return_tensors="pt")
183
+
184
+ with torch.no_grad():
185
+ outputs = model(**inputs)
186
+ logits = outputs.logits
187
+ probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
188
+
189
+ predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
190
+ # Sort by descending probability
191
+ predictions = dict(sorted(predictions.items(), key=lambda item: item[1], reverse=True)[:5])
192
+
193
+ return predictions
194
+
195
+ # Gradio Interface
196
+ iface = gr.Interface(
197
+ fn=classify_food,
198
+ inputs=gr.Image(type="numpy"),
199
+ outputs=gr.Label(num_top_classes=5, label="Top 5 Prediction Scores"),
200
+ title="Food-101-93M 🍽️",
201
+ description="Upload an image of food to classify it into one of 101 dish categories based on the Food-101 dataset."
202
+ )
203
+
204
+ # Launch app
205
+ if __name__ == "__main__":
206
+ iface.launch()
207
+ ```
208
+
209
+ ---
210
+
211
+ # **Intended Use:**
212
+
213
+ The **Food-101-93M** model is intended for:
214
+
215
+ - **Recipe Recommendation Engines:** Automatically tagging food images to suggest recipes.
216
+ - **Food Logging & Calorie Tracking Apps:** Categorizing meals based on photos.
217
+ - **Smart Kitchens:** Assisting food recognition in smart appliances.
218
+ - **Restaurant Menu Digitization:** Auto-classifying dishes for visual menus or ordering systems.
219
+ - **Dataset Labeling:** Enabling automatic annotation of food datasets for training other ML models.