|
# π§ Food-Image-Classification-AI-Model |
|
|
|
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. |
|
|
|
|
|
--- |
|
|
|
|
|
## β¨ Model Highlights |
|
|
|
- π Base Model: facebook/deit-base-patch16-224 |
|
- π Datasets: Food-101 Data |
|
- πΏ Classes: 101 food categories (e.g., pizza, ramen, steak, etc.) |
|
- π§ Framework: Hugging Face Transformers + PyTorch |
|
|
|
--- |
|
|
|
## π§ Intended Uses |
|
|
|
- β
Food image classification in apps/web |
|
- β
Educational visual datasets |
|
- β
Food blog/media categorization |
|
- β
Restaurant ordering support systems |
|
|
|
--- |
|
|
|
## π« Limitations |
|
|
|
- β May not perform well on poor-quality or mixed-food images |
|
- β Not optimized for detecting multiple food items per image |
|
|
|
|
|
--- |
|
|
|
## ποΈββοΈ Training Details |
|
|
|
| Attribute | Value | |
|
|--------------------|----------------------------------| |
|
| Base Model | facebook/deit-base-patch16-224 | |
|
| Dataset | Food-101-Dataset | |
|
| Task Type | Image Classification | |
|
| Epochs | 3 | |
|
| Batch Size | 16 | |
|
| Optimizer | AdamW | |
|
| Loss Function | CrossEntropyLoss | |
|
| Framework | PyTorch + Transformers | |
|
| Hardware | CUDA-enabled GPU | |
|
|
|
--- |
|
|
|
## π Evaluation Metrics |
|
|
|
|
|
| Metric | Score | |
|
| ----------------------------------------------- | ----- | |
|
| Accuracy | 0.97 | |
|
| F1-Score | 0.98 | |
|
| Precision | 0.99 | |
|
| Recall | 0.97 | |
|
|
|
|
|
--- |
|
|
|
--- |
|
π Usage |
|
```python |
|
from transformers import AutoImageProcessor, AutoModelForImageClassification |
|
from PIL import Image |
|
import torch |
|
from torchvision.transforms import Compose, Resize, ToTensor, Normalize |
|
|
|
# Load model and processor |
|
model_name = "AventIQ-AI/Food-Classification-AI-Model" |
|
|
|
model = AutoModelForImageClassification.from_pretrained("your-model-path") |
|
processor = AutoImageProcessor.from_pretrained("your-model-path") |
|
|
|
def predict(image_path): |
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
model.to(device) |
|
|
|
image = Image.open(image_path).convert("RGB") |
|
transform = Compose([ |
|
Resize((224, 224)), |
|
ToTensor(), |
|
Normalize(mean=processor.image_mean, std=processor.image_std) |
|
]) |
|
pixel_values = transform(image).unsqueeze(0).to(device) |
|
|
|
with torch.no_grad(): |
|
outputs = model(pixel_values=pixel_values) |
|
logits = outputs.logits |
|
predicted_idx = logits.argmax(-1).item() |
|
predicted_label = model.config.id2label[predicted_idx] |
|
|
|
return predicted_label |
|
|
|
# Example usage: |
|
print(predict("Foodexample.jpg")) |
|
|
|
``` |
|
--- |
|
|
|
- π§© Quantization |
|
- Post-training static quantization applied using PyTorch to reduce model size and accelerate inference on edge devices. |
|
|
|
---- |
|
|
|
π Repository Structure |
|
``` |
|
. |
|
beans-vit-finetuned/ |
|
βββ config.json β
Model architecture & config |
|
βββ pytorch_model.bin β
Model weights |
|
βββ preprocessor_config.json β
Image processor config |
|
βββ training_args.bin β
Training metadata |
|
βββ README.md β
Model card |
|
|
|
``` |
|
--- |
|
π€ Contributing |
|
|
|
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. |
|
|
|
|
|
|