Update README.md
Browse files
README.md
CHANGED
@@ -2,8 +2,26 @@
|
|
2 |
license: apache-2.0
|
3 |
datasets:
|
4 |
- avnishs17/food_not_food
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
---
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
```py
|
8 |
Classification Report:
|
9 |
precision recall f1-score support
|
@@ -16,4 +34,83 @@ Classification Report:
|
|
16 |
weighted avg 0.8778 0.8774 0.8773 8000
|
17 |
```
|
18 |
|
19 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
datasets:
|
4 |
- avnishs17/food_not_food
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
base_model:
|
8 |
+
- google/siglip2-base-patch16-224
|
9 |
+
pipeline_tag: image-classification
|
10 |
+
library_name: transformers
|
11 |
+
tags:
|
12 |
+
- text-generation-inference
|
13 |
+
- food
|
14 |
+
- biology
|
15 |
+
- Food-or-Not
|
16 |
---
|
17 |
|
18 |
+

|
19 |
+
|
20 |
+
# **Food-or-Not-SigLIP2**
|
21 |
+
|
22 |
+
> **Food-or-Not-SigLIP2** is a vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for **binary image classification**. It is trained to distinguish between images of **food** and **non-food** objects using the **SiglipForImageClassification** architecture.
|
23 |
+
|
24 |
+
|
25 |
```py
|
26 |
Classification Report:
|
27 |
precision recall f1-score support
|
|
|
34 |
weighted avg 0.8778 0.8774 0.8773 8000
|
35 |
```
|
36 |
|
37 |
+

|
38 |
+
|
39 |
+
---
|
40 |
+
|
41 |
+
## **Label Space: 2 Classes**
|
42 |
+
|
43 |
+
The model classifies each image into one of the following categories:
|
44 |
+
|
45 |
+
```
|
46 |
+
Class 0: "food"
|
47 |
+
Class 1: "not-food"
|
48 |
+
```
|
49 |
+
|
50 |
+
---
|
51 |
+
|
52 |
+
## **Install Dependencies**
|
53 |
+
|
54 |
+
```bash
|
55 |
+
pip install -q transformers torch pillow gradio
|
56 |
+
```
|
57 |
+
|
58 |
+
---
|
59 |
+
|
60 |
+
## **Inference Code**
|
61 |
+
|
62 |
+
```python
|
63 |
+
import gradio as gr
|
64 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
65 |
+
from PIL import Image
|
66 |
+
import torch
|
67 |
+
|
68 |
+
# Load model and processor
|
69 |
+
model_name = "prithivMLmods/Food-or-Not-SigLIP2" # Replace with your model path if different
|
70 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
71 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
72 |
+
|
73 |
+
# Label mapping
|
74 |
+
id2label = {
|
75 |
+
"0": "food",
|
76 |
+
"1": "not-food"
|
77 |
+
}
|
78 |
+
|
79 |
+
def classify_food(image):
|
80 |
+
image = Image.fromarray(image).convert("RGB")
|
81 |
+
inputs = processor(images=image, return_tensors="pt")
|
82 |
+
|
83 |
+
with torch.no_grad():
|
84 |
+
outputs = model(**inputs)
|
85 |
+
logits = outputs.logits
|
86 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
87 |
+
|
88 |
+
prediction = {
|
89 |
+
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
|
90 |
+
}
|
91 |
+
|
92 |
+
return prediction
|
93 |
+
|
94 |
+
# Gradio Interface
|
95 |
+
iface = gr.Interface(
|
96 |
+
fn=classify_food,
|
97 |
+
inputs=gr.Image(type="numpy"),
|
98 |
+
outputs=gr.Label(num_top_classes=2, label="Food Classification"),
|
99 |
+
title="Food-or-Not-SigLIP2",
|
100 |
+
description="Upload an image to detect if it contains food or not."
|
101 |
+
)
|
102 |
+
|
103 |
+
if __name__ == "__main__":
|
104 |
+
iface.launch()
|
105 |
+
```
|
106 |
+
|
107 |
+
---
|
108 |
+
|
109 |
+
## **Intended Use**
|
110 |
+
|
111 |
+
**Food-or-Not-SigLIP2** can be used for:
|
112 |
+
|
113 |
+
* **Dietary Apps** – Automatically classify images for food detection.
|
114 |
+
* **Retail & E-commerce** – Filter food vs non-food products visually.
|
115 |
+
* **Content Moderation** – Flag content containing food items.
|
116 |
+
* **Dataset Curation** – Separate food-related images for training or filtering.
|