Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π§ Food-Image-Classification-AI-Model
|
| 2 |
+
|
| 3 |
+
A Food image classification model fine-tuned on the Food-101 dataset using the powerful facebook/deit-base-patch16-224 architecture. This model classifies images into one of 101 popular food categories such as pizza, ramen, pad thai, sushi, and more.
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
## β¨ Model Highlights
|
| 10 |
+
|
| 11 |
+
- π Base Model: facebook/deit-base-patch16-224
|
| 12 |
+
- π Datasets: Food-101 Data
|
| 13 |
+
- πΏ Classes: 101 food categories (e.g., pizza, ramen, steak, etc.)
|
| 14 |
+
- π§ Framework: Hugging Face Transformers + PyTorch
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## π§ Intended Uses
|
| 19 |
+
|
| 20 |
+
- β
Food image classification in apps/web
|
| 21 |
+
- β
Educational visual datasets
|
| 22 |
+
- β
Food blog/media categorization
|
| 23 |
+
- β
Restaurant ordering support systems
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## π« Limitations
|
| 28 |
+
|
| 29 |
+
- β May not perform well on poor-quality or mixed-food images
|
| 30 |
+
- β Not optimized for detecting multiple food items per image
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## ποΈββοΈ Training Details
|
| 36 |
+
|
| 37 |
+
| Attribute | Value |
|
| 38 |
+
|--------------------|----------------------------------|
|
| 39 |
+
| Base Model | facebook/deit-base-patch16-224 |
|
| 40 |
+
| Dataset | Food-101-Dataset |
|
| 41 |
+
| Task Type | Image Classification |
|
| 42 |
+
| Epochs | 3 |
|
| 43 |
+
| Batch Size | 16 |
|
| 44 |
+
| Optimizer | AdamW |
|
| 45 |
+
| Loss Function | CrossEntropyLoss |
|
| 46 |
+
| Framework | PyTorch + Transformers |
|
| 47 |
+
| Hardware | CUDA-enabled GPU |
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## π Evaluation Metrics
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
| Metric | Score |
|
| 55 |
+
| ----------------------------------------------- | ----- |
|
| 56 |
+
| Accuracy | 0.97 |
|
| 57 |
+
| F1-Score | 0.98 |
|
| 58 |
+
| Precision | 0.99 |
|
| 59 |
+
| Recall | 0.97 |
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
---
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
π Usage
|
| 66 |
+
```python
|
| 67 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 68 |
+
from PIL import Image
|
| 69 |
+
import torch
|
| 70 |
+
from torchvision.transforms import Compose, Resize, ToTensor, Normalize
|
| 71 |
+
|
| 72 |
+
# Load model and processor
|
| 73 |
+
model_name = "AventIQ-AI/Food-Classification-AI-Model"
|
| 74 |
+
|
| 75 |
+
model = AutoModelForImageClassification.from_pretrained("your-model-path")
|
| 76 |
+
processor = AutoImageProcessor.from_pretrained("your-model-path")
|
| 77 |
+
|
| 78 |
+
def predict(image_path):
|
| 79 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 80 |
+
model.to(device)
|
| 81 |
+
|
| 82 |
+
image = Image.open(image_path).convert("RGB")
|
| 83 |
+
transform = Compose([
|
| 84 |
+
Resize((224, 224)),
|
| 85 |
+
ToTensor(),
|
| 86 |
+
Normalize(mean=processor.image_mean, std=processor.image_std)
|
| 87 |
+
])
|
| 88 |
+
pixel_values = transform(image).unsqueeze(0).to(device)
|
| 89 |
+
|
| 90 |
+
with torch.no_grad():
|
| 91 |
+
outputs = model(pixel_values=pixel_values)
|
| 92 |
+
logits = outputs.logits
|
| 93 |
+
predicted_idx = logits.argmax(-1).item()
|
| 94 |
+
predicted_label = model.config.id2label[predicted_idx]
|
| 95 |
+
|
| 96 |
+
return predicted_label
|
| 97 |
+
|
| 98 |
+
# Example usage:
|
| 99 |
+
print(predict("Foodexample.jpg"))
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
---
|
| 103 |
+
|
| 104 |
+
- π§© Quantization
|
| 105 |
+
- Post-training static quantization applied using PyTorch to reduce model size and accelerate inference on edge devices.
|
| 106 |
+
|
| 107 |
+
----
|
| 108 |
+
|
| 109 |
+
π Repository Structure
|
| 110 |
+
```
|
| 111 |
+
.
|
| 112 |
+
beans-vit-finetuned/
|
| 113 |
+
βββ config.json β
Model architecture & config
|
| 114 |
+
βββ pytorch_model.bin β
Model weights
|
| 115 |
+
βββ preprocessor_config.json β
Image processor config
|
| 116 |
+
βββ training_args.bin β
Training metadata
|
| 117 |
+
βββ README.md β
Model card
|
| 118 |
+
|
| 119 |
+
```
|
| 120 |
+
---
|
| 121 |
+
π€ Contributing
|
| 122 |
+
|
| 123 |
+
Open to improvements and feedback! Feel free to submit a pull request or open an issue if you find any bugs or want to enhance the model.
|
| 124 |
+
|
| 125 |
+
|